Jump to content

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

 

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.