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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2007
    Location
    St.Louis MO
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    strtotime(), date(), and time()

    Hi guys,

    I'm having a couple of issues with using strtotime(), date(), and time().

    The first is: I used strtotime() to get the unix of a specific date and time (worked great, even outputted the correct time using date() to return it). However when I went to post information on it (I set it up so that you can't post after the event started), it told me it already started like an hour before it was supposed to. I used

    PHP Code:
    if (time() > $event['when']) { echo "too late."; } else { do it 
    to determine whether you can post or not. That had me very confused.

    Then I decided instead of manually inputting the event times I would pull them from an xml file, which I had no trouble reading.

    I used:
    PHP Code:
    $day "Sun";
    $time "1:00";
    strtotime("Next $day, $time PM"
    This outputted a unix timestamp but then date() returned it as being 7 pm on sunday instead.

    Any ideas what would be causing these strange things?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    strtotime() is pretty strict about the format of the date you put in as a string.

    See this page of formats.
    Look at the relative formats.

    I *think* you need to skip the comma and PM and use the 24hr clock.
    Last edited by tangoforce; 11-24-2011 at 12:45 AM.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    Corey (11-26-2011)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Have you specified the date_default_timezone_set as well? Functions like date() are locale aware and will format according to their timezone. These are often UTC.

    PHP's documentation for strtotime is terrible honestly. Use this link instead: http://www.gnu.org/software/tar/manu...t-formats.html
    strtotime should ignore the comma.

  • Users who have thanked Fou-Lu for this post:

    Corey (11-26-2011)

  • #4
    New Coder
    Join Date
    Nov 2007
    Location
    St.Louis MO
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the replies. The problem was I had the timezone set in the header of the config file. I found out that it had to be assigned within the static method.

    PHP Code:
    static function Game_Info($game$options NULL)
    {
        
    date_default_timezone_set('EST');
        if (
    is_array($game))
        {
            if (isset(
    $options['shorten_team']))
            {
                
    $game['home_team'] = self::team_name($game['home_team']);
                
    $game['away_team'] = self::team_name($game['away_team']);
            }
            if (isset(
    $options['date']))
            {
                
    $game['when'] = date('D M j G:i:s T Y'$game['when']);
            }
            else
            {
                
    $game['when'] = date('D \@ g\:i A'$game['when']);
            }
            return 
    $game;
        }
    }
    static function 
    Get_All($group NULL$options NULL)
    {
        
    $return = array();
        
    $time_sec strtotime(date('m') . '/' . (date('d') - 2) . '/' date('Y'));
        
    $get_games Sports_Database::Build_Query('SELECT''games'"`when` > '" $time_sec "'");
        while (
    $game $get_games->FetchRow())
        {
            if (
    $group == 'lid')
            {
                
    $return[$game['league_id']][] = self::Game_Info($game$options);
            }
            else
            {
                
    $return[] = self::Game_Info($game);
            }
        }
        return 
    $return;



  •  

    Posting Permissions

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