Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    AOD
    AOD is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Assign value to a variable depending on time

    How do I assign a value to a variable depending on the time of the day?

    For example: If time is between 2am to 4pm, variable = 50.

    How can I accomplish this?

    Thanks for any help.

  • #2
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    403
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As long as you remember that you are dealing with a 24 hour clock, and have a firm grasp of greater/lesser than and greater/lesser or equal to, it's no problem.

    PHP Code:
    <?
    $switchvar 
    0;
    $hour date('H');
    if (
    $hour <= 16 and $hour >= 2$switchvar 50
    echo 
    $switchvar;
    ?>
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #3
    AOD
    AOD is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Feyd. That would get me started.

    What if I want to breakdown the variable assignment in 30-minute intervals for example?

    How do I use the date function to return the value in minutes or seconds?

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Minutes is i (00 - 59), seconds is s (00-59)

    IE:

    $minute = date('i');

    Or

    $second = date('s');


  • #5
    AOD
    AOD is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But that would only give me values from 0 to 60 for a given hour or for a given minute.

    I want the date function to return values in seconds or minutes for a day instead of just 0 to 23 (using the "G" format).

    Like so:

    0 to 1440 (one whole day by the minutes)

    0 to 86400 (one whole day by the seconds)


    For example between 7:16 am to 7:46 am, variable = 12. The "G" format is inadequate for this.

    Any ideas?

  • #6
    New Coder
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe u should try to do like this

    $hour = date('H);
    $minute = date('i');
    $second = date('s');'

    # now u can calculate how many seconds elapsed so far today!

    $number = ($hour*60*60)+($minute*60)+$second;

    # then u do assign any value to your variable acording to $number.

    hope it helped.


  • #7
    AOD
    AOD is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks djbruno it helped.

    Or I can also try something like this:

    if (strftime("%H:%M",time())>"14:00" && strftime("%H:%M",time())<"16:00")
    $variable=50;
    elseif ......


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •