Page 1 of 1

mysql query based on todays date

Posted: Sun Sep 20, 2009 12:47 am
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?

Re: mysql query based on todays date

Posted: Sun Sep 20, 2009 5:05 am
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.

Re: mysql query based on todays date

Posted: Sun Sep 20, 2009 2:58 pm
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: