Vidya_tr Posted April 28, 2009 Share Posted April 28, 2009 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..... Quote Link to comment https://forums.phpfreaks.com/topic/155943-problem-in-date-datatype/ Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 Most likely strtotime doesn't work with DD-MM-YYYY mm:hh format. Quote Link to comment https://forums.phpfreaks.com/topic/155943-problem-in-date-datatype/#findComment-820888 Share on other sites More sharing options...
Vidya_tr Posted April 28, 2009 Author Share Posted April 28, 2009 what format can I use for strtotime if I want to convert a string "27-04-2009 10:55" to a date format?? Quote Link to comment https://forums.phpfreaks.com/topic/155943-problem-in-date-datatype/#findComment-820890 Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155943-problem-in-date-datatype/#findComment-820892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.