0

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

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

1

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"]); 

2 Comments

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 ;-)
good catch on strtotime(); I'm so used to using it I wasn't paying much attention

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.