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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.