Jump to content

date/strtotime Y-m-d into m-d-Y


powpow

Recommended Posts

Hey freaks,

 

running into a little issue with the use of date and strtotime....

 

basically I wanna present the date in the format m-d-y to the user and insert it into the DB in the Y-m-d format. 

 

What seems to be happening is a freaky Y-d-m format and I don't know why this is.  This code is an example that expresses my frustration.

 

$nmon = strtotime("next Monday");
$next = date('m-d-Y', $nmon);
$_SESSION['REPORT_DUE'] = $next;


$nfri = strtotime("Friday");
$due = date('m-d-Y', $nfri);
$_SESSION['WEEK_ENDING'] = $due;
$ses1 = $_SESSION['WEEK_ENDING2'] = date('Y-m-d', strtotime($due));
$ses2 = $_SESSION['WEEK_ENDING3'] = date('d-m-Y', strtotime($ses1));

 

 

.....output....

 

[WEEK_ENDING] => 09-02-2011 [WEEK_ENDING2] => 2011-02-09 [WEEK_ENDING3] => 09-02-2011 )

 

 

Thank you for any assistance.

Link to comment
https://forums.phpfreaks.com/topic/246220-datestrtotime-y-m-d-into-m-d-y/
Share on other sites

strtotime() doesn't support M-D-Y strings. If you try it will assume it's D-M-Y and parse it as such (and if that doesn't work then it fails).

 

Your options:

a) Don't strtotime() that string. Get a number for a date and never use strtotime() again. Best option

b) Use slashes like M/D/Y (which does work)

c) Switch to D-M-Y. You probably don't want to

touche.....  :-\

 

$nextfri = strtotime("next Friday");
$due1 = date('m-d-Y', $nextfri);
echo "<br>" . $due1 . "<br>";
$due2 = date('Y-m-d', $nextfri );
echo $due2 . "<br>";
$due3 = date('d-m-Y', $nextfri );
echo $due3 . "<br>";

 

09-02-2011

2011-09-02

02-09-2011

 

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.