If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > question about date and time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-04, 22:41
sunnyside sunnyside is offline
Registered User
 
Join Date: Aug 2003
Posts: 30
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 11:51.
Reply With Quote
  #2 (permalink)  
Old 10-13-04, 07:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
select min(from_unixtime(`time`)) from yourtable
where from_unixtime(`time`) > '2004-10-12 14:20'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-13-04, 11:53
sunnyside sunnyside is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 10-13-04, 13:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you realize that the `time` field has the date included, right? so you don't need the date_2 column at all
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On