powpow Posted September 1, 2011 Share Posted September 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246220-datestrtotime-y-m-d-into-m-d-y/ Share on other sites More sharing options...
jcbones Posted September 1, 2011 Share Posted September 1, 2011 $nfri = strtotime("next Friday"); Quote Link to comment https://forums.phpfreaks.com/topic/246220-datestrtotime-y-m-d-into-m-d-y/#findComment-1264510 Share on other sites More sharing options...
requinix Posted September 1, 2011 Share Posted September 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246220-datestrtotime-y-m-d-into-m-d-y/#findComment-1264513 Share on other sites More sharing options...
powpow Posted September 1, 2011 Author Share Posted September 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246220-datestrtotime-y-m-d-into-m-d-y/#findComment-1264518 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.