SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: I'm Dying Here

  1. #1
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm Dying Here

    A while ago I posted this question, and was directed to the MySQL manual. Unfortunatly it has been a week and I still cannot get this select staement working. Any help would be greatly appreciated.

    I have a DATE stamp that looks like this in MySQL:

    1051434951

    I need to pull all entries for a specific MONTH. Is there a way?

    -Taylor

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by rockyracoon
    A while ago I posted this question, and was directed to the MySQL manual. Unfortunatly it has been a week and I still cannot get this select staement working. Any help would be greatly appreciated.

    I have a DATE stamp that looks like this in MySQL:

    1051434951

    I need to pull all entries for a specific MONTH. Is there a way?

    -Taylor
    That looks like a TIMESTAMP.

    Maybe do something like this? :


    PHP Code:
    <?php

    $lowTime 
    strtotime ("1 January 2003");
    $highTime strtotime ("31 January 2003");

    $query "select blah from blah_blah where timeField > $lowTime and 
              timeField < 
    $highTime";


    ?>
    To use the strtotime() function more precisely check out the "Date input formats" link from this page:
    http://www.php.net/manual/en/function.strtotime.php ..

    --ed

  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coo_t2
    That looks like a TIMESTAMP.

    Maybe do something like this? :
    PHP Code:
    <?php

    $lowTime 
    strtotime ("1 January 2003" );
    $highTime strtotime ("31 January 2003" );

    $query "select blah from blah_blah where timeField > $lowTime and 
    timeField < 
    $highTime";


    ?>
    To use the strtotime() function more precisely check out the "Date input formats" link from this page:
    http://www.php.net/manual/en/function.strtotime.php ..

    --ed
    This would be what you are looking for:

    http://www.php.net/manual/en/function.date.php
    John

  4. #4
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot guys, I will try this tonight.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rockyracoon
    Thanks a lot guys, I will try this tonight.
    You could do this just using MySQL (always my preference where possible)
    Code:
    SELECT cols FROM table WHERE MONTH(FROM_UNIXTIME(1051434951)) = <monthNumber>;
    If you would rather specify a name of a month then replace MONTH with MONTHNAME.

  6. #6
    SitePoint Evangelist rockyracoon's Avatar
    Join Date
    Apr 2003
    Location
    Burbank
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "1051434951" why do I include this? I would not know this value untill I have selected it... Maybe I'm missing something.

  7. #7
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rocky,

    Read up on the function mktime()

    This will return a timestamp that you can use in your query. If you are going to be looking for a particular month, you may want to run it this way:
    PHP Code:
    // for the month of January, 2003
    $monthStart mktime(00011date("Y" ));
    $monthEnd mktime(000131date("Y" ));

    $query "SELECT cols FROM table WHERE timestampField > $monthStart AND timestampField < $monthEnd
    John


Bookmarks

Posting Permissions

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