Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    30

    Unanswered: question about date and time

    Hi, I have a table which has fields: date_1(format: 2004-10-12), time(UNIX timestamp: 1097586000), date_2(same format with "date_1") ... the "time" is time happen on the "date_2", but not "date_1".

    My question is: If there is a given date and time (2004-10-12, 14:20), how can I find the first time just follow this specific date and time.

    For example: data in my table:

    2004-10-1 12:19 2004-09-01
    2004-10-12, 14:19 2004-08-12
    2004-10-12, 14:21 2004-10-10
    2004-10-14, 14:20 2004-10-11

    I just want the 3rd record found, cause it's the date and time just follow the given date and time (2004-10-12, 14:20).


    Thank you!
    Last edited by sunnyside; 10-13-04 at 12:51.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select min(from_unixtime(`time`)) from yourtable
    where from_unixtime(`time`) > '2004-10-12 14:20'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2003
    Posts
    30
    Quote Originally Posted by r937
    select min(from_unixtime(`time`)) from yourtable
    where from_unixtime(`time`) > '2004-10-12 14:20'
    Sorry, my mistake. the "time" field is the time happened on date_2, but not date_1. In this example I gave, if using "from_unixtime(`time`) > '2004-10-12 14:20'", will no result returned. because the latest date on my table is the last row's 2004-10-11

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you realize that the `time` field has the date included, right? so you don't need the date_2 column at all
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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