iPixel Posted March 2, 2011 Share Posted March 2, 2011 I pass a variable (date) which contains the date in format of 03-02-2011 (m-d-Y) how could i quickly change that date format to show 02-MAR-2011 (d-M-Y) Is there a function that can quick do this? Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/ Share on other sites More sharing options...
Zane Posted March 2, 2011 Share Posted March 2, 2011 yeah, the date() function date(strtotime("03-02-2011"), "d-M-Y"); Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181914 Share on other sites More sharing options...
Rifts Posted March 2, 2011 Share Posted March 2, 2011 <?php $date = $yourvar; echo $date->format('d-M-Y'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181915 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 $date = '03-02-2011'; echo strtoupper(date('d-M-Y', strtotime($date))); Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181917 Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 @Zanus... isnt your strtotime() missing a parameter? @Rifts format is a function i do not have. Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181918 Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 $date = '03-02-2011'; echo strtoupper(date('d-M-Y', strtotime($date))); THis returns 31-DEC-1969 and that is definately not the date in teh $date variable. Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181919 Share on other sites More sharing options...
Rifts Posted March 2, 2011 Share Posted March 2, 2011 format is built into php so you do have it. http://php.net/manual/en/datetime.format.php Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181920 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 $date = '03-02-2011'; echo strtoupper(date('d-M-Y', strtotime($date))); THis returns 31-DEC-1969 and that is definately not the date in teh $date variable. I've tested that locally, and it works fine with php 5.2.11. What do you get if you echo your $date variable before passing it through the functions? Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181923 Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 I think this will serve best as to help me figure this out... <?php error_reporting(E_ALL); ini_set('display_errors','On'); $start = $_GET['start']; //02-23-2011 is the date passed in this $_GET[]; //Convert dates to ORACLE format $start2 = date_format($start, 'd-M-Y'); $end = strtoupper(date('d-M-Y', strtotime('today'))); echo $start; echo " -=- "; echo $end; echo "<BR><BR>"; echo $start2; // Should be ORACLE FORMAT echo " --- "; echo $end; ?> Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181925 Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 OK problem solved... i was passing 02-23-2011 which aparently confuses the heck out of php.. if i pass 23-02-2011 it works fine. i guess the given format has to be month day year and no other way around it. Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181930 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2011 Share Posted March 2, 2011 The - separator expects dd [.\t-] mm [.-] YY http://www.php.net/manual/en/datetime.formats.date.php Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181941 Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 The - separator expects dd [.\t-] mm [.-] YY http://www.php.net/manual/en/datetime.formats.date.php Like wise / expects the other: echo date('M d Y',strtotime('02/20/1971')); echo date('M d Y',strtotime('20-02-1971')); Quote Link to comment https://forums.phpfreaks.com/topic/229391-whats-the-quickest-most-efficient-way-to-change-date-format/#findComment-1181943 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.