AV1611 Posted September 14, 2007 Share Posted September 14, 2007 I working a script that pulls some dates from an ODBC source with php. The dates pulled look like this: yyyy-mm-dd I need them to display as mm/dd/yyyy I can't figure it out, and the manual doesn't give an example for date_format() if that is even what I want... HELP! Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/ Share on other sites More sharing options...
pocobueno1388 Posted September 14, 2007 Share Posted September 14, 2007 <?php $date = "yyyy-mm-dd"; list($year, $month, $day) = explode("-", $date); echo "$month/$day/$year"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348549 Share on other sites More sharing options...
darkfreaks Posted September 14, 2007 Share Posted September 14, 2007 <?php date(m/j/y); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348551 Share on other sites More sharing options...
AV1611 Posted September 14, 2007 Author Share Posted September 14, 2007 <?php $date = "yyyy-mm-dd"; list($year, $month, $day) = explode("-", $date); echo "$month/$day/$year"; ?> LOL That was my backup plan, I thought there was some fancy date format way to do it Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348555 Share on other sites More sharing options...
darkfreaks Posted September 14, 2007 Share Posted September 14, 2007 topic solved? Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348556 Share on other sites More sharing options...
pocobueno1388 Posted September 14, 2007 Share Posted September 14, 2007 There may be a way to do with with one line with the date function...I'm not sure. If there is, I don't know how to do it Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348563 Share on other sites More sharing options...
Jessica Posted September 14, 2007 Share Posted September 14, 2007 you can combine date with strtotime. Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348565 Share on other sites More sharing options...
darkfreaks Posted September 14, 2007 Share Posted September 14, 2007 nice idea jesi i just looked it up $timestamp = strtotime( "07/9/14" ); print date( 'Y-m-d', $timestamp ); Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348571 Share on other sites More sharing options...
Psycho Posted September 14, 2007 Share Posted September 14, 2007 Why create a variable for a onetime use? Just use: print date( 'Y-m-d', strtotime( "07/9/14" )); Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348581 Share on other sites More sharing options...
darkfreaks Posted September 14, 2007 Share Posted September 14, 2007 wouldnt that still output the same thing without it? Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348589 Share on other sites More sharing options...
Psycho Posted September 14, 2007 Share Posted September 14, 2007 wouldnt that still output the same thing without it? It will first create the timestamp and then date() willact on that. I copied your example which is not what the OP wanted. This is what the OP wanted: <?php //Input in YYYY-MM-DD //Output in MM/DD/YYYY print date( 'm/d/Y', strtotime( "2007-09-14" )); //Output: 09/14/2007 ?> Quote Link to comment https://forums.phpfreaks.com/topic/69372-solved-i-hate-dates/#findComment-348663 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.