Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql and dates

Status
Not open for further replies.

ph1b3r

Programmer
Joined
May 4, 2007
Messages
2
Location
AR
I have a table like this:

user | date | value |
-------|------------|-----------|
mark | 13/04/2007 | 1
peter | 11/04/2007 | 2
peter | 10/04/2007 | 1
mark | 11/04/2007 | 3
peter | 01/04/2007 | 10
mark | 01/04/2007 | 1
mark | 04/03/2007 | 34
peter | 01/03/2007 | 3

i need make a select who give me value where the date its the more near to NOW() for any user.

thanks!
 
Code:
select user
     , date
     , value
  from daTable as mysister
 where date =
       ( select max(date)
           from daTable
          where user = mysister.user
            and date <= current_date )

r937.com | rudy.ca
 
rudy's query won't work for you. it will when you convert your invalid dates that are in char/varchar format to yyyymmdd format with an actual DATE type. Use STR_TO_DATE to convert them.
 
i use mysql 4.0.

i gonna try this one. ;)
 
This item will explain how to update your table by creating a new date type column and converting your dates. you can do this while being on mysql 4.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top