EchoFool Posted January 4, 2009 Share Posted January 4, 2009 Hey I have a query which i want to update a time stamp in one of my field to be X amount of days different to what it is. So what i mean is this: Say the timestamp says: 2008-01-01 00:00:00 Now i want to make it 14 days before that timestamp using a query...at first i thought that should be simple but then i realised it isn't because the year and month would become 2007-12 etc etc Can this be done in one simple update query..if not how can i do such maths to a timestamp like that? Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/ Share on other sites More sharing options...
DarkWater Posted January 4, 2009 Share Posted January 4, 2009 UPDATE table SET field = DATE_SUB(field, INTERVAL 14 DAY); Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/#findComment-729510 Share on other sites More sharing options...
jandante@telenet.be Posted January 4, 2009 Share Posted January 4, 2009 I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code: function isOpenNow($account) { $toreturn; $today = date("w"); echo $today; $hour = date("G:i:s"); echo $hour; $query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today; $result_getHours = mysql_query($query_getHours) or die(mysql_error()); if(mysql_result($result_getHours, 'open') == true) { if(mysql_result($result_getHours, 'whole_day') == true) { // now we only need to check starting hours and end hours $starthour = mysql_result($result_getHours, 'start_morning'); $endhour = mysql_result($result_getHours, 'end_afternoon'); if($starthour < $hour < $endhour) { echo "Open for the whole day and you can still go"; } } } else { echo "Closed"; } } Now I get the error: Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181 Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)). So < is an unexpected character in my code? I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41 Should I compare Time's otherwise? Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/#findComment-729514 Share on other sites More sharing options...
EchoFool Posted January 4, 2009 Author Share Posted January 4, 2009 I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code: function isOpenNow($account) { $toreturn; $today = date("w"); echo $today; $hour = date("G:i:s"); echo $hour; $query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today; $result_getHours = mysql_query($query_getHours) or die(mysql_error()); if(mysql_result($result_getHours, 'open') == true) { if(mysql_result($result_getHours, 'whole_day') == true) { // now we only need to check starting hours and end hours $starthour = mysql_result($result_getHours, 'start_morning'); $endhour = mysql_result($result_getHours, 'end_afternoon'); if($starthour < $hour < $endhour) { echo "Open for the whole day and you can still go"; } } } else { echo "Closed"; } } Now I get the error: Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181 Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)). So < is an unexpected character in my code? I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41 Should I compare Time's otherwise? Think its cos your suppose to put: (if($starthour < $hour && $starthour< $endhour)) Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/#findComment-729515 Share on other sites More sharing options...
EchoFool Posted January 4, 2009 Author Share Posted January 4, 2009 UPDATE table SET field = DATE_SUB(field, INTERVAL 14 DAY); Thank you DarkWater will give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/#findComment-729516 Share on other sites More sharing options...
premiso Posted January 4, 2009 Share Posted January 4, 2009 I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code: function isOpenNow($account) { $toreturn; $today = date("w"); echo $today; $hour = date("G:i:s"); echo $hour; $query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today; $result_getHours = mysql_query($query_getHours) or die(mysql_error()); if(mysql_result($result_getHours, 'open') == true) { if(mysql_result($result_getHours, 'whole_day') == true) { // now we only need to check starting hours and end hours $starthour = mysql_result($result_getHours, 'start_morning'); $endhour = mysql_result($result_getHours, 'end_afternoon'); if($starthour < $hour < $endhour) { echo "Open for the whole day and you can still go"; } } } else { echo "Closed"; } } Now I get the error: Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181 Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)). So < is an unexpected character in my code? I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41 Should I compare Time's otherwise? Don't hijack threads. Create your own. Quote Link to comment https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/#findComment-729517 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.