zgkhoo Posted December 23, 2007 Share Posted December 23, 2007 given $row[Expireddate]= 2007-12-23 00:00:00 i wanna compare it with date("Y-m-d")....but the above variable contain time..which not compatible. thks... Link to comment https://forums.phpfreaks.com/topic/82905-how-to-eliminate-the-time/ Share on other sites More sharing options...
Daniel0 Posted December 23, 2007 Share Posted December 23, 2007 $date = substr($row['Expiredate'], 0, 10); Will get the date part of string. You could also use strtotime() to convert it to a UNIX timestamp. Link to comment https://forums.phpfreaks.com/topic/82905-how-to-eliminate-the-time/#findComment-421624 Share on other sites More sharing options...
kenrbnsn Posted December 23, 2007 Share Posted December 23, 2007 You can also use the explode() function: <?php list($date , $dmy) = explode(' ',$row['Expiredate']); ?> Personally, since we're dealing with dates, I would use the date() and strtotime() functions: <?php $date = date('Y-m-d',strtotime($row['Expiredate'])); ?> You can also use MySQL directly to return the correct format, but I don't know the correct incantation off the top of my head. Ken Link to comment https://forums.phpfreaks.com/topic/82905-how-to-eliminate-the-time/#findComment-421684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.