Skip to content
WJunction - Webmaster Forum

mysql php - select * where date = today?

Status
Not open for further replies.

c0rrup

Established Member
352
2009
1
Hello, I am trying to do a mysql query to get all the rows where date = "today".....

The problem is, I store my downloads date using:
$date = time();

is a mysql text field, which I'm guessing is really bad / slow?

Can anyone provide me with a better way to store dates and then also provide me with a mysql_query to select all that have been added today.


Thank you.
 

10 comments

Date should be a numeric 11 byte int field for the date storing. Be sure to use a key index of the date.
for Today only
select * from table WHERE substring(from_unixtime(my_date),1,10) = CURDATE()
 
Yes, all timestamps should be set as int.

I would avoid using any extra MySQL processing, though, especially since you're generating your original timestamp with PHP's time().

Something like this would suffice:

Code:
$today = strtotime('12:00:00');

$sqlQuery = "SELECT * FROM theTable WHERE the_time >= {$today}";
 
If you create a time stamp within PHP, you should compare it with PHP. Mostly because within the PHP system, an offset may be used within the time function or the date_default_timezone_set. Inconsistent code is really bad programming.
 
You are kidding. Right? Where did you get your Mysql training?

So you want to create a variable in php and read the the mysql data and move the date field to a php on each record then compare?

Well that is exactly what you just said. You just don't quit do you.. Nothing in your head but book learning. No real experience in database design and implementation.

It is your opinion but keep it to yourself.
 
You're brilliant.

You'd rather two functions be executed over every row to make a comparison. Instead of one simple comparison, you'd rather over complicate it in an irrational way.

I lack experience? Yeah... that's why you're telling someone to use an expensive string function and an unnecessary timestamp conversion on EVERY ROW.
 
if u dont understand time() or mktime(), just store ur dates using date field. google mysql date

if ur storing using time(), change ur field type to INT, since its faster then using VARCHAR or CHAR or similar.
 
You're 100% right. It's perfectly logical that a query with two functions is faster than one with 0 functions.

Again, sheer brilliance.
 
Again a stupid answer from a underdeveloped mind.

I'll bet if you just keep posting trash for points sooner or later staff will catch you.
 
Status
Not open for further replies.

About the author

C
Established Member · Joined
352
Messages
1
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom