Page 1 of 1

Running a query using todays date

Posted: Fri Jul 09, 2004 1:30 pm
by Shaman
I am trying to create a query which will use today's date as a parameter. I am using MySQL and Php 4.1. My code thus far is as follows

Code: Select all

<?PHP
$result = mysql_query( "SELECT * FROM ttime where (SNUM = '".$_SESSION['SNUM']."')  and TIDATE = Date() ORDER BY TIDATE DESC")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print  "You currently have $num_rows time entries for today.</font><P>";
?>
The table I am running the query against is ttime and the field that holds the date value is TIDATE. I want the query to use the session value of the user SNUM and todays date to pull up the record set.

The practical reason for doing this is the user SNUM adds time records for time spent on various activities throughout the day into the table ttime. My query is intended to allow the user to query the database to create a record set of those records they have added today. I am stumped as to how to get the query to use today's date in the mm/dd/yyyy format as a parameter. Any and All Help is Appreciated!


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Jul 12, 2004 4:12 pm
by hawleyjr
Is your date being stored as a date field or a text field?

Whenever you are storing a date in a db store it as a date yyyy-mm-dd

In doing so you will be able to write a query such as:

Code: Select all

$qry = "Select * where dttm = now()";
Also, check out MySQL Manualregarding date types.

Hope this helps.

-J