Jump to content


Photo

how to sort by a date range?


  • Please log in to reply
6 replies to this topic

#1 flyclassic

flyclassic
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 June 2006 - 10:10 AM

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

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 24 June 2006 - 11:42 AM

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.
SELECT * FROM $table WHERE date ='2006-06-24'
Where $table is the table..

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 June 2006 - 10:45 PM

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... WHERE DATE_FORMAT(date, '%Y[span style=\'color:orange\']-%m-%d'[/span]) = '2006[span style=\'color:orange\']-06-24'[/span] [!--sql2--][/div][!--sql3--]
or
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]... WHERE date BETWEEN '2006[span style=\'color:orange\']-06-24 00:00:00'[/span] AND '2006[span style=\'color:orange\']-06-24 23:59:59'[/span] [!--sql2--][/div][!--sql3--]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 flyclassic

flyclassic
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 25 June 2006 - 06:42 AM

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


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

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 07:57 AM

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\" /]
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 June 2006 - 10:43 AM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 flyclassic

flyclassic
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 25 June 2006 - 11:19 AM

hahah, what's the debate all about?
Who's genius? I think both are better than moi!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users