i have been trying to convert a posted parameter from a textbox like '12/09/2008' m/d/Y to 'Y/d/m' but seem to be deleting the date when im trying to pass a variable instead of a string : see
$startDate = $_POST['arrival'];
$endDate = $_POST['departure'];
$ArrivalDate = new DateTime("@$startDate");
$DepartureDate = date("Y-d-m",strtotime("@$endDate"));
echo $ArrivalDate->format("Y/m/d");
echo $DepartureDate."<br>";
but both give me the same result. this 1970-01-01. Why?
the php version has been updated to the version 5.2.6
regards.
format date
Moderator: General Moderators
Re: format date
So I try your code with "12/09/2008" for both dates and I get
Then I fix it (by removing the @) and I get
As far as I can tell it's working fine.
Code: Select all
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (@12/09/2008) at position 3 (/): Unexpected character' in X:Y
Stack trace:
#0 X(Y): DateTime->__construct('@12/09/2008')
#1 {main}
thrown in X on line YCode: Select all
2008/12/092008-09-12<br>- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: format date
Code: Select all
function user_date_mysql($date, $format) {return date ($format, strtotime($date));}
//function call example...
echo user_date_mysql($row1['thread_date'], "l F jS, Y, h:iA");http://php.net/date