
Hi guys, Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff? Scenario: StartTime = 0600 EndTime = 1800 TimeNow = 0950 An algorithm like If TimeNow >= StartTime and <= EndTime then allow would work However, this will not work if the Start/End time spans across 2 days: StartTime = 1800 EndTime = 0600 TimeNow = 0550 Using the logic will fail yet 0550 is logically within the preset timeframe

Why not have a more comprehensive time stamp that includes date and time? On 2 May 2013 09:54, Bwana Lawi <mail2lawi@gmail.com> wrote:
Hi guys,
Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff?
Scenario:
StartTime = 0600 EndTime = 1800
TimeNow = 0950
An algorithm like
If TimeNow >= StartTime and <= EndTime then allow
would work
However, this will not work if the Start/End time spans across 2 days:
StartTime = 1800 EndTime = 0600
TimeNow = 0550
Using the logic will fail yet 0550 is logically within the preset timeframe
_______________________________________________ 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
-- with Regards: blog.denniskioko.com <http://www.denniskioko.com/>

I would just include date information in the timestamp. Any timestamp you get from a library will already have that information in it anyway. The real question is, why are you doing this yourself. Surely, whatever language you use has a date comparison library and can handle this situation with a simple method. Reinventing the wheel, especially with a domain as intractable as dates and times, is a 'bad' idea. Let us know what you come up with though. Cheers, Adam https://twitter.com/varud https://www.linkedin.com/in/adamcnelson On Thu, May 2, 2013 at 8:54 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Hi guys,
Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff?
Scenario:
StartTime = 0600 EndTime = 1800
TimeNow = 0950
An algorithm like
If TimeNow >= StartTime and <= EndTime then allow
would work
However, this will not work if the Start/End time spans across 2 days:
StartTime = 1800 EndTime = 0600
TimeNow = 0550
Using the logic will fail yet 0550 is logically within the preset timeframe
_______________________________________________ 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

Its a parameter that needs to be checked any time a certain function is run. The requirement is that that function can only be run within specific times. (start time and end time) There is no limitation to the day as it is a user invoked function On Thu, May 2, 2013 at 9:58 AM, Adam Nelson <adam@varud.com> wrote:
I would just include date information in the timestamp. Any timestamp you get from a library will already have that information in it anyway.
The real question is, why are you doing this yourself. Surely, whatever language you use has a date comparison library and can handle this situation with a simple method. Reinventing the wheel, especially with a domain as intractable as dates and times, is a 'bad' idea.
Let us know what you come up with though.
Cheers, Adam
https://twitter.com/varud https://www.linkedin.com/in/adamcnelson
On Thu, May 2, 2013 at 8:54 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Hi guys,
Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff?
Scenario:
StartTime = 0600 EndTime = 1800
TimeNow = 0950
An algorithm like
If TimeNow >= StartTime and <= EndTime then allow
would work
However, this will not work if the Start/End time spans across 2 days:
StartTime = 1800 EndTime = 0600
TimeNow = 0550
Using the logic will fail yet 0550 is logically within the preset timeframe
_______________________________________________ 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

In Python, I would create a decorator to run the timestamp check and attach that to the method. The decorator would return something like Method Not Allowed if the timestamps are not in the correct range. But without more information, this is tough to answer. I would send this question to one of the lists for the language in which this is being written since they'll know the libraries very well and can point you to the right solution quickly. And then of course there's Stack Overflow ... https://twitter.com/varud https://www.linkedin.com/in/adamcnelson On Thu, May 2, 2013 at 8:59 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Its a parameter that needs to be checked any time a certain function is run.
The requirement is that that function can only be run within specific times. (start time and end time)
There is no limitation to the day as it is a user invoked function
On Thu, May 2, 2013 at 9:58 AM, Adam Nelson <adam@varud.com> wrote:
I would just include date information in the timestamp. Any timestamp you get from a library will already have that information in it anyway.
The real question is, why are you doing this yourself. Surely, whatever language you use has a date comparison library and can handle this situation with a simple method. Reinventing the wheel, especially with a domain as intractable as dates and times, is a 'bad' idea.
Let us know what you come up with though.
Cheers, Adam
https://twitter.com/varud https://www.linkedin.com/in/adamcnelson
On Thu, May 2, 2013 at 8:54 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Hi guys,
Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff?
Scenario:
StartTime = 0600 EndTime = 1800
TimeNow = 0950
An algorithm like
If TimeNow >= StartTime and <= EndTime then allow
would work
However, this will not work if the Start/End time spans across 2 days:
StartTime = 1800 EndTime = 0600
TimeNow = 0550
Using the logic will fail yet 0550 is logically within the preset timeframe
_______________________________________________ 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
_______________________________________________ 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

@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

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.

in C# I would convert all the time to *DateTime.Now.Tick*; using this you can then do logical comparison and even convert the tick back to date time. I had once used this trick for calculating leave days and eliminating weekends and public holidays from counting leave days. Let me know if you need the actual algorithm in C# regards, Paul Roy. On Thu, May 2, 2013 at 10: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
-- "Change is slow and gradual. It requires hardwork, a bit of luck, a fair amount of self-sacrifice and a lot of patience." Roy.

The start/end times are preset (of course configurable). It is not that a specific function/app should run at the preset time. It's a parameter set to restrict at what times of the day, any day, a function can be run - and there are many different functions. (This one is an extraction that should only be run during the non-busy hours, i.e. at night). As for timestamp, yes, I can get the exact date and time of the current time. But the issue is how do I check that that time is within the preset start/end time? Remember the start/end time are not limited to a date. On Thu, May 2, 2013 at 10: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

@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

@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 -------------------

@Peter, Thanks for that. Unfortunately the parameters do not set the start_date_time and end_date_time. Just start_time and end_time. Think of it this way: How would you implement for an application that only allows the users to log in ONLY from 1800 to 0600? If the user tries to log in any other time of the day the system should lock him/her out. On Thu, May 2, 2013 at 10:49 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@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 -------------------
_______________________________________________ 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

Adam, read my question carefully. No need to be snide about it. I have stated again that the starttime and endtime cannot be tied to a date. Otherwise this would have been a simple comparison of julian times 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

I apologize if I sounded snide - no offense was intended. Anyway, your second email clarified things greatly and now I understand. In Python, you need the 'time' object which is an idealized 24 hour day: -----
import datetime a = datetime.datetime.now() a datetime.datetime(2013, 5, 2, 10, 42, 36, 877059) d = datetime.time(10, 42, 00) e = datetime.time(10, 43, 00) bool(d <= a.time() < e) True
https://twitter.com/varud https://www.linkedin.com/in/adamcnelson On Thu, May 2, 2013 at 9:50 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Adam, read my question carefully.
No need to be snide about it. I have stated again that the starttime and endtime cannot be tied to a date.
Otherwise this would have been a simple comparison of julian times
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
_______________________________________________ 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

@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?] 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
-- Kore Francis Njenga Running and Walking are only breaths apart.

Adding 24 to both endtime and current time when the endtime is less than starttime seems to work. On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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

@Lawi, for my edification; when you say "users to log in ONLY from 1800 to 0600", do you mean: 1. 1800 today to 0600 tomorrow OR 2. 0600 to 1800 *any day?* On Thu, May 2, 2013 at 11:02 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Adding 24 to both endtime and current time when the endtime is less than starttime seems to work.
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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 -------------------

Guessing that your time stamps are in the db. use MYSQL ..... IF ( CURRENT_TIMESTAMP<http://www.tutorialspoint.com/mysql/mysql-date-time-functions.htm#function_current-timestamp>() BETWEEN start_date AND end_date, 1, 0) That would return a Boolean (1 or 0) if your current_time_stamp is between the start & end dates .. On Thu, May 2, 2013 at 11:11 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, for my edification; when you say "users to log in ONLY from 1800 to 0600", do you mean:
1. 1800 today to 0600 tomorrow OR 2. 0600 to 1800 *any day?*
On Thu, May 2, 2013 at 11:02 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Adding 24 to both endtime and current time when the endtime is less than starttime seems to work.
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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 -------------------
_______________________________________________ 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

@Peter, sorry for the late reply On Thu, May 2, 2013 at 11:11 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, for my edification; when you say "users to log in ONLY from 1800 to 0600", do you mean:
1. 1800 today to 0600 tomorrow OR 2. 0600 to 1800 *any day?*
For some reason this post is not in my threads. To answer your question, it is ANY DAY. Not tomorrow. As long as the current (server) time is not between those two times the user should not be able to log in. @Ken, The params in the db are for time, not date. Anyway, if the start time is less than end time (meaning they fall on same day) I can do a direct compare. If end time is less than start time, meaning the interval rolls into the next day then all i did was add 24 to both end time and the current time (for comparison) Then I did the same if

@Lawi ... To my understanding Time always have a date.. but if inyour case 0600 or 1800 i don't think that can get you a date... My Question is Why would you want to store 0600 or 1800 into the db ? you have less control of the output.. i would have preferred a unixtimestamp or a datetime.. TRY THIS SELECT DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') AS _hour, IF ( DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') BETWEEN 1300 AND 1500, 1, 0) AS _check always replace my 1300 and 1500 to your variables................ On Thu, May 2, 2013 at 1:21 PM, Bwana Lawi <mail2lawi@gmail.com> wrote:
@Peter, sorry for the late reply
On Thu, May 2, 2013 at 11:11 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, for my edification; when you say "users to log in ONLY from 1800 to 0600", do you mean:
1. 1800 today to 0600 tomorrow OR 2. 0600 to 1800 *any day?*
For some reason this post is not in my threads.
To answer your question, it is ANY DAY. Not tomorrow. As long as the current (server) time is not between those two times the user should not be able to log in.
@Ken, The params in the db are for time, not date.
Anyway, if the start time is less than end time (meaning they fall on same day) I can do a direct compare.
If end time is less than start time, meaning the interval rolls into the next day then all i did was add 24 to both end time and the current time (for comparison)
Then I did the same if
_______________________________________________ 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

@Ken, if you are to set up a parameter for what times users are allowed to log in how would you store that parameter? On Thu, May 2, 2013 at 1:56 PM, Ken Muturi <muturiken@gmail.com> wrote:
@Lawi ...
To my understanding Time always have a date.. but if inyour case 0600 or 1800 i don't think that can get you a date... My Question is Why would you want to store 0600 or 1800 into the db ? you have less control of the output.. i would have preferred a unixtimestamp or a datetime..
TRY THIS
SELECT DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') AS _hour, IF ( DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') BETWEEN 1300 AND 1500, 1, 0) AS _check
always replace my 1300 and 1500 to your variables................
On Thu, May 2, 2013 at 1:21 PM, Bwana Lawi <mail2lawi@gmail.com> wrote:
@Peter, sorry for the late reply
On Thu, May 2, 2013 at 11:11 AM, Peter Karunyu <pkarunyu@gmail.com>wrote:
@Lawi, for my edification; when you say "users to log in ONLY from 1800 to 0600", do you mean:
1. 1800 today to 0600 tomorrow OR 2. 0600 to 1800 *any day?*
For some reason this post is not in my threads.
To answer your question, it is ANY DAY. Not tomorrow. As long as the current (server) time is not between those two times the user should not be able to log in.
@Ken, The params in the db are for time, not date.
Anyway, if the start time is less than end time (meaning they fall on same day) I can do a direct compare.
If end time is less than start time, meaning the interval rolls into the next day then all i did was add 24 to both end time and the current time (for comparison)
Then I did the same if
_______________________________________________ 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

@Bwana Lawi - Just to throw a spanner into the works - is it guaranteed that the task will be completed within 24hrs? or does the system reset every 24 hours?
Anyway, if the start time is less than end time (meaning they fall on same day) I can do a direct compare.
What if the task starts today at 8am and ends tomorrow at 9am - then the above assumption wont work.

@Billy, thanks for the spanner :) The check is only done at the instantiation of the function. Not for the whole period while the function is running. On Thu, May 2, 2013 at 2:24 PM, Billy <billyx5@gmail.com> wrote:
@Bwana Lawi - Just to throw a spanner into the works - is it guaranteed that the task will be completed within 24hrs? or does the system reset every 24 hours?
Anyway, if the start time is less than end time (meaning they fall on same day) I can do a direct compare.
What if the task starts today at 8am and ends tomorrow at 9am - then the above assumption wont work.
_______________________________________________ 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

Hahaha been watching this battle of wits and smiled this code can be written in many forms as many have describe I only think that @Lawi wanted you to think what he was thinking which is impossible time stamp works adding + or -24 to start and end time works but the base line is time stamp I must say by arguing that if I log in now then to get if the time is within the range you certainly going to add or minus from log on time and how do you get that time????????????/ MY assumptions NOT yOUR decision On Thu, May 2, 2013 at 11:02 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
Adding 24 to both endtime and current time when the endtime is less than starttime seems to work.
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- MICHAEL A. AKUNGA Cell No: (+254) ( 0) 726 174 815 E-Mail: michaelakunga@gmail.com michaelakunga@yahoo.com Blog: http://michysoft.blogspot.com Skype: michaelakunga

@Lawi, whether you like it or not, time IS tied to a date, because time cannot exist in the absence of a date. So if users can only login between 1800Hrs on the current day and 0600Hrs the next day, the day still exists, only that its *rolling.* Does that make sense? On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- Regards, Peter Karunyu -------------------

@Peter, check this out: http://stackoverflow.com/questions/10631044/c-sharp-compare-time-between-two... On Thu, May 2, 2013 at 11:02 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, whether you like it or not, time IS tied to a date, because time cannot exist in the absence of a date.
So if users can only login between 1800Hrs on the current day and 0600Hrs the next day, the day still exists, only that its *rolling.*
Does that make sense?
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- Regards, Peter Karunyu -------------------
_______________________________________________ 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

Thanx everyone, sorted now On Thu, May 2, 2013 at 11:05 AM, Bwana Lawi <mail2lawi@gmail.com> wrote:
@Peter, check this out:
http://stackoverflow.com/questions/10631044/c-sharp-compare-time-between-two...
On Thu, May 2, 2013 at 11:02 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, whether you like it or not, time IS tied to a date, because time cannot exist in the absence of a date.
So if users can only login between 1800Hrs on the current day and 0600Hrs the next day, the day still exists, only that its *rolling.*
Does that make sense?
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- Regards, Peter Karunyu -------------------
_______________________________________________ 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

I agree with @Ashok, scheduling the task using cron jobs at the operating system level seems like the most intuitive way to approach @Lawi's problem. On Windows or other non UNIX-like O.Ss, use the "Scheduled Tasks" application or something similar. If I was to go with @Adam's way but write the system in JAVA I would use annotations <http://en.wikipedia.org/wiki/Java_annotation> which are just the opposite numbers to Python's decorators. I would have written the code to illustrate my point, but laziness as you all know is a virtue to any programmer worth his / her salt :-) Martin. On Thu, May 2, 2013 at 11:02 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, whether you like it or not, time IS tied to a date, because time cannot exist in the absence of a date.
So if users can only login between 1800Hrs on the current day and 0600Hrs the next day, the day still exists, only that its *rolling.*
Does that make sense?
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- Regards, Peter Karunyu -------------------
_______________________________________________ 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

@martin Laziness is indeed the mark of a virtuous programmer https://twitter.com/varud https://www.linkedin.com/in/adamcnelson On Thu, May 2, 2013 at 10:11 AM, Martin Chiteri <martin.chiteri@gmail.com>wrote:
I agree with @Ashok, scheduling the task using cron jobs at the operating system level seems like the most intuitive way to approach @Lawi's problem. On Windows or other non UNIX-like O.Ss, use the "Scheduled Tasks" application or something similar.
If I was to go with @Adam's way but write the system in JAVA I would use annotations <http://en.wikipedia.org/wiki/Java_annotation> which are just the opposite numbers to Python's decorators. I would have written the code to illustrate my point, but laziness as you all know is a virtue to any programmer worth his / her salt :-)
Martin.
On Thu, May 2, 2013 at 11:02 AM, Peter Karunyu <pkarunyu@gmail.com> wrote:
@Lawi, whether you like it or not, time IS tied to a date, because time cannot exist in the absence of a date.
So if users can only login between 1800Hrs on the current day and 0600Hrs the next day, the day still exists, only that its *rolling.*
Does that make sense?
On Thu, May 2, 2013 at 10:51 AM, Francis Njenga <korefn@gmail.com> wrote:
@Adam not knowing the offending language, a concrete solution is as a pain so making sure he knows that specific fact('In the abstract') would have sufficed IMHO. [?]
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
-- 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
-- Regards, Peter Karunyu -------------------
_______________________________________________ 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

You should perhaps be doing this a cron job on your operating system. Have one cron to start the task at a particular time and second one to terminate it at the required end time . Ashok On 2 May 2013 09:54, Bwana Lawi <mail2lawi@gmail.com> wrote:
Hi guys,
Programmers, what algorithm would you use to check that a given time (current timestamp in 24hr) is within a preset start and end times and if so, do specific stuff?
Scenario:
StartTime = 0600 EndTime = 1800
TimeNow = 0950
An algorithm like
If TimeNow >= StartTime and <= EndTime then allow
would work
However, this will not work if the Start/End time spans across 2 days:
StartTime = 1800 EndTime = 0600
TimeNow = 0550
Using the logic will fail yet 0550 is logically within the preset timeframe
_______________________________________________ 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
participants (11)
-
Adam Nelson
-
ashok+skunkworks@parliaments.info
-
Billy
-
Bwana Lawi
-
Dennis Kioko
-
Francis Njenga
-
Ken Muturi
-
Martin Chiteri
-
Mickey Mickey
-
Paul Roy
-
Peter Karunyu