
@Adam and @Lawi, as a way of procrastinating working, I also tried using PHP: <?php //this assumes that the start time is the same every day, i.e. every day at 0600Hrs, the output below is e.g. 2013-05-02 06:00 $start_day_time = date('Y-m-d 06:00'); $start_day_time_timestamp = strtotime($start_day_time); echo "Start time: $start_day_time. Timestamp: $start_day_time_timestamp <br/>"; //this assumes that the end date is the same every day, i.e. every day at 1800Hrs, the output below is e.g. 2013-05-02 18:00 $end_day_time = date('Y-m-d 18:00'); $end_day_time_timestamp = strtotime($end_day_time); $end_day_time_timestamp = mktime(0, 0, 0, date("m") , date("d")+2, date("Y")); echo "End time: $end_day_time. Timestamp: $end_day_time_timestamp <br/>"; /* What if the end time is 2 days from today, at 1800Hrs? $end_day_time_timestamp = mktime(0, 0, 0, date("m") , date("d")+2, date("Y")); */ //so what is the timestamp now? $now_timestamp = strtotime("now"); echo "Now: $now_timestamp <br/><br/><br/>"; //based on the start and end timestamps, are we allowed to run now? if ($now_timestamp >= $start_day_time_timestamp AND $now_timestamp <= $end_day_time_timestamp) { echo 'Yay! It can run!'; } else { echo 'Nope! No run.'; } ?> On Thu, May 2, 2013 at 10:46 AM, Adam Nelson <adam@varud.com> wrote:
@francis I think he's using the word 'timestamp' loosely as the time of day. But yes, as everyone agrees so far, just use the timestamp which has all the date information and then comparison is trivial.
Since we all seem to be having fun wasting time on a Thursday, I did it in Python for demonstration purposes. I set 'a' to now and then 'b' to now a few seconds later and then arbitrarily set 'c' to a time within the period. This is date-sensitive.
---------------- ➜ ~ python Python 2.7.3 (default, Dec 5 2012, 11:30:37) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type "help", "copyright", "credits" or "license" for more information.
import datetime a = datetime.datetime.now() a datetime.datetime(2013, 5, 2, 10, 42, 36, 877059) b = datetime.datetime.now() b datetime.datetime(2013, 5, 2, 10, 42, 50, 684714) c = datetime.datetime(2013, 5, 2, 10, 42, 49, 000000) c datetime.datetime(2013, 5, 2, 10, 42, 49) bool(a <= b < c) False bool(a <= c < b) True
https://twitter.com/varud https://www.linkedin.com/in/adamcnelson
On Thu, May 2, 2013 at 9:37 AM, Francis Njenga <korefn@gmail.com> wrote:
A timestamp will have all these details and you can extract the relevant details from it. I.e. datetime has both date and time. You can use the time or date where relevant. This is the essence of a timestamp.
On Thu, May 2, 2013 at 10:31 AM, Peter Karunyu <pkarunyu@gmail.com>wrote:
@Lawi, does the start times change per day or are they sorta fixed at a preset time?
Say, every day at 0600Hrs is the start, and every day at 1800Hrs is the end
_______________________________________________ skunkworks mailing list skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Kore Francis Njenga Running and Walking are only breaths apart.
_______________________________________________ skunkworks mailing list skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ skunkworks mailing list skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu -------------------