chiefrokka Posted February 17, 2008 Share Posted February 17, 2008 I'm trying to compare a Deadline with current Date. it's returning -1 for Deadline. do i have the right syntax? the HTML form is Month, Day, Year, Hour, PM ex: 2 16 2008 11 PM $Deadline = date("U", strtotime(" ".$PickDeadline_Month." ".$PickDeadline_Day." ".$PickDeadline_Year." ".$PickDeadline_Hour." ".$PickDeadline_PM." ")); $Today = date("U"); echo "<br>Deadline = ".$Deadline.""; echo "<br>Today = ".$Today.""; Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/ Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 try '2008-02-16 11 PM' Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469000 Share on other sites More sharing options...
wildteen88 Posted February 17, 2008 Share Posted February 17, 2008 In order for strtotime to return a unix timestamp it requires a valid english readable date, eg: 2/16/2008 23:00 not 2 16 2008 11 PM You might want to look into mktime rather than strtotime. Also no need to use date either to convert the value strtotime returns as it already returns a unixtime stamp. Another thing which is not required (and irritates me - no offense) is ending lines with empty strings after/before using a variable (.""); Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469001 Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 Another thing which is not required (and irritates me - no offense) is ending lines with empty strings after/before using a variable (.""); Agreed. I often see people doing it though. Is there a book out there where the author advocates such usage? Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469007 Share on other sites More sharing options...
chiefrokka Posted February 17, 2008 Author Share Posted February 17, 2008 try '2008-02-16 11 PM' I need to use those variable names because the admin will be changing the Deadline to whatever they want. can someone change the code to what it should be if I was just using variable names? I'm still trying to understand this whole strtotime and date. as for the empty strings """ before/after I think it's just cuz i'm used to using echo "test = ".$var.""; Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469010 Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 <?php $Deadline = strtotime("{$PickDeadline_Year}-{$PickDeadline_Month}-{$PickDeadline_Day} $PickDeadline_Hour $PickDeadline_PM"); Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469017 Share on other sites More sharing options...
chiefrokka Posted February 17, 2008 Author Share Posted February 17, 2008 <?php $Deadline = strtotime("$PickDeadline_Year-$PickDeadline_Month-$PickDeadline_Day $PickDeadline_Hour $PickDeadline_PM"); cool thanks. I'm testing it now and I think it's working Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469036 Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 my edited version should be safer Link to comment https://forums.phpfreaks.com/topic/91562-strtotime-syntax/#findComment-469040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.