ainoy31 Posted December 12, 2007 Share Posted December 12, 2007 Hello- I need a second eye on this. I have a date format that is in 22/12/2007. I pass this data over to the next page to convert into 2007-12-22. However, this is my issue. Instead, I get a date of 1969-12-31. Here is my code: $date = $_POST["ship_date"]; $ship_date = date("Y-m-d", $strtotime($date)); echo "Ship Date: " . $ship_date . "<br>"; Much appreciation. AM Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/ Share on other sites More sharing options...
dsaba Posted December 12, 2007 Share Posted December 12, 2007 $strtotime($date)); if strtotime is supposed to be a function there shouldn't be a $ in front of it $ (dollar signs) precede variables, not functions Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412644 Share on other sites More sharing options...
ainoy31 Posted December 12, 2007 Author Share Posted December 12, 2007 That was I typo on my part. $date = $_POST["ship_date"]; $ship_date = date("Y-m-d", strtotime($date)); I still get the 1969-12-31 value. Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412648 Share on other sites More sharing options...
rajivgonsalves Posted December 12, 2007 Share Posted December 12, 2007 from my expierience I don't think it accepts dd/mm/yyyy format it however accepts mm/dd/yyyy format. Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412649 Share on other sites More sharing options...
dsaba Posted December 12, 2007 Share Posted December 12, 2007 if strtotime() has trouble accepting your format and you can use mktime() to send in the parameters manually, you can parse the date string yourself to get the arguments Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412651 Share on other sites More sharing options...
Lumio Posted December 12, 2007 Share Posted December 12, 2007 what is in $_POST['ship_date']? Maybe not that, what you need Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412653 Share on other sites More sharing options...
ainoy31 Posted December 12, 2007 Author Share Posted December 12, 2007 Here is my solution: $date = $_POST["ship_date"]; $d = explode('/', $date); $yr = $d[2]; $mo = $d[1]; $dy = $d[0]; $ar = array('year' => $yr, 'mon' => $mo, 'day' => $dy); $ship_date = implode("-", $ar); echo "Ship Date: " . $ship_date . "<br>"; This gave me the format that I needed. yyyy-mm-dd. Thanks for all the suggestions. Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412665 Share on other sites More sharing options...
beansandsausages Posted December 12, 2007 Share Posted December 12, 2007 Here is my solution: $date = $_POST["ship_date"]; $d = explode('/', $date); $yr = $d[2]; $mo = $d[1]; $dy = $d[0]; $ar = array('year' => $yr, 'mon' => $mo, 'day' => $dy); $ship_date = implode("-", $ar); echo "Ship Date: " . $ship_date . "<br>"; This gave me the format that I needed. yyyy-mm-dd. Thanks for all the suggestions. what does explode & implode do. Never heard of them before. Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412667 Share on other sites More sharing options...
dsaba Posted December 12, 2007 Share Posted December 12, 2007 what does explode & implode do. Never heard of them before. I heard someone mention the word "google" the other day. What does it mean/do? Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412669 Share on other sites More sharing options...
beansandsausages Posted December 12, 2007 Share Posted December 12, 2007 was only a question, never heard them used in a php script Link to comment https://forums.phpfreaks.com/topic/81305-solved-strtotime/#findComment-412674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.