Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-12-2011, 07:56 PM MySQL query help...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Hi,

I have this situation on my hands, I need to display only todays links from the db, but the db table shows a row called date_added and the date is specified as month day, year format: Ex: June 12, 2011. How can I output only the rows with 'todays' date? Meaning tomorrow will be June 13, 2011, so only those will be on the page etc..

Thank you
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-12-2011, 08:00 PM Re: MySQL query help...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Something like:
Code:
SELECT col from tbl where day(date_col) = day(now());
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-12-2011, 08:22 PM Re: MySQL query help...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Something like:
Code:
SELECT col from tbl where day(date_col) = day(now());
That didn't quite work Matt, I get 0 results for that query. No errors, just 0 results, and I am sure there's a link in the database with todays date.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 06-12-2011, 08:28 PM Re: MySQL query help...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Just to clarify, is the datatype for the date column either 'date' or 'timestamp'?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-12-2011, 08:37 PM Re: MySQL query help...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Just to clarify, is the datatype for the date column either 'date' or 'timestamp'?
Nope, varchar is the datatype...I don't know if I should change the datatype either, could that corrupt the script, needing another re-install?
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 06-12-2011 at 08:39 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 06-12-2011, 08:43 PM Re: MySQL query help...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try
Code:
select col from tbl where date(str_to_date(date_col, '%M %d, %Y')) = date(now());
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-12-2011, 08:48 PM Re: MySQL query help...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Try
Code:
select col from tbl where date(str_to_date(date_col, '%M %d, %Y')) = date(now());
Still 0, but still no errors. Wait! The date is shown like this: 12 June 2011 (my mistake on the original post -- No seperation in the date either other than spaces, exactly as I posted is how it is in the db: 12 June 2011) so maybe the %M %d, %Y is wrong?
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 06-12-2011 at 08:53 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 06-12-2011, 08:54 PM Re: MySQL query help...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Yes, just remove the comma and the format should be correct.

In the future, if you're storing dates in a database it is best to use either the date or timestamp format.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-12-2011, 09:01 PM Re: MySQL query help...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Yes, just remove the comma and the format should be correct.

In the future, if you're storing dates in a database it is best to use either the date or timestamp format.
Thank you Matt! Works as expected. Btw, the script was from linkstation pro for reciprocals, I found it to be better to use a pre-made script than to figure out the scripting, I like to leave that up to the pros. I just pretend to be one sometimes.
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 06-12-2011 at 09:02 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to MySQL query help...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28726 seconds with 12 queries