Computing.Net > Forums > Database > querying dates

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

querying dates

Reply to Message Icon

Name: timothy_aah
Date: June 6, 2009 at 08:40:41 Pacific
OS: Windows XP
Subcategory: MySQL
Comment:

hi,

I have a column containing dates (date datatype)
now a user can select a date via php or whatever,
the result the user has to get is the data stored for the previous date
for example:

date1 x1 y1 z1
date2 x2 y2 z2
date3 x3 y3 z3

now if the user selects date2 the result should be x1,y1,z1
if the user selects date3 the result should be x2,y2,z2

the dates are completely random, so I need a query that will look for the date previous to the one selected without using any further data from the table!
how would I accomplish this?
thx :)

edit:
dates are also randomly added, so indexing them is of no use since the order of the indexes will not match that of the dates



Sponsored Link
Ads by Google

Response Number 1
Name: DESTRUCTO
Date: June 10, 2009 at 22:24:25 Pacific
Reply:

you can do the following in mysql.

select year(date2) - 1,month(date2)-1,day(date2)-1
from Sometable.

This will return the values of the dates from the preceding date.

This could work if all the dates are incremented by 1 for each value.


0

Response Number 2
Name: timothy_aah
Date: June 11, 2009 at 05:47:21 Pacific
Reply:

thx for your input, but dates are not incremented by 1 for each value, like I said, they're completely random...
let me give you a clearer example:

2009-02-05 x1 y1 z1
2009-04-18 x2 y2 z2
2009-06-06 x3 y3 z3

so if the user selects 2009-06-06, the data from the previous date has t be returned, in this case x2,y2,z2
so here your solution will not work, and it's goind to be like this in most cases, if not all cases...

I guess I could just query all dates meeting certain criteria, order them, and then in php for example put them in an array and use a for-loop to get the info, but that seems bloated to me
+ after a while these queries are going to give a lot of rows so I don't want to have to load them all into my front code...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: querying dates

Access Date Query www.computing.net/answers/dbase/access-date-query/733.html

Access 2000 query www.computing.net/answers/dbase/access-2000-query/232.html

Access 2000 query result www.computing.net/answers/dbase/access-2000-query-result/272.html