Jump to content

problem in DATE datatype


Vidya_tr

Recommended Posts

I have a form which posts two dates with time to another page.

The date and time are taken as string using $_POST

$fromdate=$_POST['day1']."-".$_POST['month1']."-".$_POST['year1']."".$_POST['hrs1'].":".$_POST['min1']."<br>";
echo "fromdate as string:".$fromdate."\n";//prints the posted vale
$fromdate=date('Y-m-d H:i:s',strtotime($fromdate));
echo "fromdate:".$fromdate."\n";//prints the wrong value

$todate=$_POST['day2']."-".$_POST['month2']."-".$_POST['year2']." ".$_POST['hrs2'].":".$_POST['min2']."<br>";
echo "todate as string:".$todate."\n";
$todate=date('Y-m-d H:i:s',strtotime($todate));
echo "todate:".$todate."\n";

 

 

I convert the string to date format using date('Y-m-d H:i:s',strtotime($fromdate));

But when I try to print the converted string it prints only the date and not the time

i.e for example if I have a string value as "27-04-2009 10:55" in $fromdate,

date('Y-m-d H:i:s',strtotime($fromdate)); gives me the value 1970-01-01 00:00:00 ,but not the correct value.

 

what is the error in printing the date?

How can I correct it?

Please help me.....

Link to comment
https://forums.phpfreaks.com/topic/155943-problem-in-date-datatype/
Share on other sites

I think that having <br> at he end of your date might have something to do with it:P

 

And anyway, why use strtotime, when you already have all the parts of the date in an array? Just put them in desired order. It will be a lot faster than strtotime.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.