tags:

views:

36

answers:

2

Hi guys I was wondering if you could help me if the folliwng:

I have a calendar that inserts dates in hidden fields like this:

    <input name="selDay_start1" type="hidden" id="selDay_start1" />
    <input name="selMonth_start1" type="hidden" id="selMonth_start1" />
    <input name="selYear_start1" type="hidden" id="selYear_start1" />
    <input name="selDay_end1" type="hidden" id="selDay_end1" />
    <input name="selMonth_end1" type="hidden" id="selMonth_end1" />
    <input name="selYear_end1" type="hidden" id="selYear_end1" />

I need to get informations for the first 3 (start date) and combine them in a date to be inserted in a mysql table. The same thing for the next 3 (end date). Does anyone know how to combine those date in the form of yyyy/mm/dd? Many thanks for any help Francesco

+1  A: 

If you just need to combine it then this should work

$date = $_REQUEST["selYear_start1"] . "/" . $_REQUEST["selMonth_start1"] . "/" . $_REQUEST["selDay_start1"];

If you need to create timestamp from the string use the strtotime function

$date = strtotime($_REQUEST["selYear_start1"] . "/" . $_REQUEST["selMonth_start1"] . "/" . $_REQUEST["selDay_start1"]);
Marek Karbarz
Thank you Marek, will go with this hope will work fine.
francesco
A minor nitpick... The `strtotime()` function doesn't create a date object. It creates a timestamp. The `date_create()` function creates an actual date object ;-)
Atli
good catch on `strtotime()`; I'm so used to using it I wasn't paying much attention
Marek Karbarz
+2  A: 

One option would be to take a look at php's mktime() and date() functions. This has the advantage of making sure you have a valid date input, instead of something bogus (such as February 31st).

Amber