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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with date()

    Hello,

    I am working on making a now playing/coming up next list for our website, shows run from 30mins to 3 hour blocks of time, I have tried to use date() to get the hours and mins then do an if else list to compare the values. But I am running into the problem of date being a string. Could anyone give me some pointers on how to convert the date output into a format that I can use to compare the hours and mins from? Any help would be appreciated.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    To compare dates/times it is best to compare them as timestamps. The mktime() function forms timestamps from dates/times. The strtotime() function is also useful in converting dates/times into timestamps.

    Without more information about what you are doing the comparison for and how the results are being used, that is as specific of an answer as you can get. You need to post your code and an example of what your data is and an example of what you are trying to accomplish.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, CFMaBiSmAd

    I will give it a try. Basicly the comparison is to find the range of time a show runs and put the show in the now playing box and display the coming up next show. So I was trying to get the date using date('Gi') to get the time ie 1023 and then use that in if else block to find the show. I have also split it using 2 date() calls as in the example.

    example

    Code:
    <?php
    $hday = date('G');
    $mday = date('i');
    $show = '';
    $upnext = '';
    
    	if ($hday = 6 & $mday < 29)
    	{
    	// Joyce Meyer
    	$show = "<h3>Joyce Meyer</h3>";
    	$upnext = "<h3>Ken Copeland</h3>";
    	}
    	else if ($hday = 6 & $mday > 29)
    	{
    	// Ken Copeland
    	$show = "<h3>Ken Copeland</h3>";
                 $upnext ="<h3>Benny Hinn</h3>";
    	}
    	else if ($hday = 7 & $mday < 29)
    	{
    	// Benny Hinn
    	$show = "<h3>Benny Hinn</h3>";
                 $upnext = "<h3>Recipe Tv</h3>";
    	}
    etc.

    this is just rough sample of it. Still new to php so might be overlooking something simple, but i think its because I am using date and the date output is considered a string and not a true number. will try using mktime(), strtotime() and see if i can get it. Thank you again for the suggestion.


  •  

    Posting Permissions

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