bickyz Posted February 25, 2011 Share Posted February 25, 2011 hi i have a mysql table with upddate and updtime field as follows: upddate updtime 2011-02-25 11:03:05 2011-01-28 08:01:09 2011-02-20 07:00:08 2011-02-15 06:10:02 2011-02-05 10:21:04 2011-02-09 10:20:25 the data types for upddate is mysql date and for updtime its mysql time In my php page i use <?php echo $date = date("d M Y",strtotime($row_rs1['upddate'])); ?> to retrieve date and the results displays as 25 Feb 2011. And for time right now im using <?php echo $row_rs1['updtime']; ?> which displays time as 11:03:05 I want to display time as HH:MM only, how can i do it? Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/ Share on other sites More sharing options...
Altrozero Posted February 25, 2011 Share Posted February 25, 2011 A kinda hacky way would be <?php echo substr($row_rs1['updtime'],0,5); ?> Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1179586 Share on other sites More sharing options...
Muddy_Funster Posted February 25, 2011 Share Posted February 25, 2011 Format from within you SELECT. SELECT DATE_FORMAT(upddate, '%d %b %Y') UpDate, TIME_FORMAT(updtime, '%H:%i) UpTime FROM tablename Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1179609 Share on other sites More sharing options...
bickyz Posted February 28, 2011 Author Share Posted February 28, 2011 is there php code instead of mysql like this one <?php echo $date = date("d M Y",strtotime($row_rs1['upddate'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1180817 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Is the time field in 24 hour format or 12 hour format? Ken Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1180820 Share on other sites More sharing options...
bickyz Posted February 28, 2011 Author Share Posted February 28, 2011 24 hr format Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1180822 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 what's wrong with doing it in the SQL? Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1180825 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Use <?php list ($date,$time) = explode(' ',date('d M Y H:i',strtotime("{$row_rs1['upddate']} {$row_rs1['updtime']}"))); echo "$date $time"; ?> But doing it in the MySQL query would be simpler. Ken Quote Link to comment https://forums.phpfreaks.com/topic/228809-retrieve-date-and-time-from-mysql-field-using-strtotime/#findComment-1180828 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.