Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

PHP Help

Started by TimCorless, January 10, 2006, 09:24:12 PM

Previous topic - Next topic


I'm trying to write some PHP which takes in a date from the user, with each part being a seperate inputtable field, ie, hours, minutes, day, month, year etc are all their own edit box.

I then have to concatenate these, convert them to a timestamp, insert them into a database for later retrieval.

This isn't working at the minute, in fact it fails before it even gets to the database:

   // get components of a date
   $day = $_POST['day'];
   $month = $_POST['month'];
   $year = $_POST['year'];

   // add the compnents of date to make a real date
   $date = "$day-$month-$year";

   // get components of a time
   $hours = $_POST['hours'];
   $minutes = $_POST['minutes'];

   // add the components of time to make a real time
   $time = "$hours:$minutes:00";

   // get the place
   $place = $_POST['place'];

   // get the comments
   $comments = $_POST['comments'];

   // need to convert date and time on their own into a Timestamp
   // so concatenate them, then use strtotime to convert them into a
  // timestamp, and store this in a new variable.
   $datetime = "$date $time GMT";
   echo $datetime;

   $gigdate = strtotime($datetime, 0);
   echo $gigdate;

   $gigdate1 = strftime('%H %M %d %m %Y', $gigdate);
   echo $gigdate1;

with the input:
21 06 2006

21 00

produces (see echo statements):

21-06-2006 21:00:00 GMT
13 00 27 11 2026

so as you see, the second date, when the timestamp is converted back into a string is completely different than what went in to the timestamp.

Can anyone see what I'm doing wrong?!

webzone (archived)

strtotime expects a date following the GNU date input formats.

One of the possible formats is 2004-02-29 16:21:42 -0800
Notice that it is formed like YYYY-MM-DD, the opposite of what you did.

Try $date = "$year-$month-$day"; and $datetime = "$date $time +0000"; instead