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... Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.