Jump to content

Archived

This topic is now archived and is closed to further replies.

flyclassic

how to sort by a date range?

Recommended Posts

Hi,i've a logic question anybody can help??

if i've following mysql database
(primary key id, `date_entry` datetime default NULL,)
id | information | date_entry |
01| handsome | 2006-06-24 18:06:19 |
02| handsome1 | 2006-06-24 18:36:12 |
03| handsome 2 | 2006-06-23 19:06:13 |
etc...


I want to select * columns from date 2006-06-24 only regardless of time OR how do i select by a given date range, how do i go about doing that? any help will be greatly appreciated. THanks

Share this post


Link to post
Share on other sites
I"m not very sure about it, but you could create 1 more column and seperate date and time.

It's easier to select using seperated date and time.
[code]SELECT * FROM $table WHERE date ='2006-06-24'[/code]
Where $table is the table..

Share this post


Link to post
Share on other sites
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... [color=green]WHERE[/color] DATE_FORMAT(date, [color=red]'%Y[span style=\'color:orange\']-[/color]%m[color=orange]-[/color]%d'[/span]) [color=orange]=[/color] [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24'[/span] [!--sql2--][/div][!--sql3--]
or
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... [color=green]WHERE[/color] date BETWEEN [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24 00:00:00'[/span] [color=blue]AND[/color] [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24 23:59:59'[/span] [!--sql2--][/div][!--sql3--]

Share this post


Link to post
Share on other sites
[!--quoteo(post=387580:date=Jun 24 2006, 05:45 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 24 2006, 05:45 PM) [snapback]387580[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... [color=green]WHERE[/color] DATE_FORMAT(date, [color=red]'%Y[span style=\'color:orange\']-[/color]%m[color=orange]-[/color]%d'[/span]) [color=orange]=[/color] [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24'[/span] [!--sql2--][/div][!--sql3--]
or
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... [color=green]WHERE[/color] date BETWEEN [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24 00:00:00'[/span] [color=blue]AND[/color] [color=red]'2006[span style=\'color:orange\']-[/color]06[color=orange]-[/color]24 23:59:59'[/span] [!--sql2--][/div][!--sql3--]
[/quote]


PHEW!, this is cooly great help! THANK YOU GUYS!

Share this post


Link to post
Share on other sites
if you have a sql question, just cross your fingers and pray that barand will descend upon your thread.

I swear he wrote the sql language [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post


Link to post
Share on other sites
I wish I had, but that honour goes to Codd's team at IBM in 1979 and later taken up by the Oracle lot too. I've only been using it since about 1985, and the MySQL version for about 4 years.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.