Forum Moderators: coopster

Message Too Old, No Replies

How best to merge date varibles?

What is the best way to merge the varibles into a date

         

djburg42

1:10 am on Jun 11, 2004 (gmt 0)

10+ Year Member



Hi all...

Sorry for the basic question, but I'm fairly new to PHP. Granted, the frustration level gets a little high at times, but I enjoy it...

Anyway, I'm trying to take three fields that come out of a function (separate from my form) and merge them together into the MySQL date format. In other words, the function feeds me back "year", "month" and "day" and I want to get it to year-month-day.

Suggestions?

jatar_k

4:51 am on Jun 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld djburg42,

in what exact format does it give them back?

3 individual variables?
an array with 3 elemants?
hyphenated?
with slashes?

djburg42

11:50 am on Jun 11, 2004 (gmt 0)

10+ Year Member



Thank you Jatar!

The values come back in 3 separate components. Basicaly it's coming out of a series of 3 dropdowns which create this date. The function creates these dropdowns. After posting the form and printing all the POST variables, it displays these as:

year=
month=
day=

Thanks for any help you can provide.

inwebsys

1:04 pm on Jun 11, 2004 (gmt 0)

10+ Year Member



Check out PHP's date and mktime functions:


$y = 1998;
$m = 12;
$d = 2;

$m_date = date("Y-m-d", mktime(0, 0, 0, $m, $d, $y));

echo $m_date;