mysql query based on todays date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

mysql query based on todays date

Post by edawson003 »

For some reason, this isn't working. Any thoughts?

Code: Select all

 
$dtfoodcntquery = "SELECT * FROM FoodLib WHERE creatdt = $date";
 
Also, I swipe this off a forum, but is not accurate PST date:

Code: Select all

 
<?php
$my_t=getdate(date("U"));
print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");
?> 
 
It says september 20, sunday eventhough it is still technically saturday over here. Is there a way to set the time zone dynamically, so depending upon where a user is, they get the right date. Any thoughts?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql query based on todays date

Post by requinix »

1.

Code: Select all

SELECT * FROM FoodLib WHERE creatdt = 2009-09-20
Take a guess what's wrong.

2. That code is the PHP equivalent of "wordy". It's like whoever wrote it wanted to make it more complicated than it needed to be. All of that is equivalent to

Code: Select all

echo date("l, F j, Y");
For timezones check out date_default_timezone_set.
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Re: mysql query based on todays date

Post by edawson003 »

K. Thanx. This works:

Code: Select all

 
$dtfoodcntquery = "SELECT * FROM FoodLib WHERE creatdt = (CURDATE())";
 
You are right, that other bit was wordy. :lol:
Post Reply