Jump to content

how to sort by a date range?


flyclassic

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
Link to comment
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..
Link to comment
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--]
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.