Forum Moderators: coopster
What i want to do is Have a list of so many things created on one day .. and then be able to pull that date out of the database ..
SO if i stored 10 things on the 8/july/2003 (time stamp 1057626025) how would i got about pulling only the ones i did today on the 8th july?
Thanks
karl
The DATETIME, DATE, and TIMESTAMP Types [mysql.com]
and given that the date format for mysql is YYYY-MM-DD then I don't really see any grand need to deviate from that. The following wil get todays date
$today = getdate() [ca.php.net];
$dayofweek = $today["weekday"];
$day = $today["mday"];
$month = $today["mon"];
$year = $today["year"];
if (strlen [ca.php.net]($month)) $month = "0" . $month;
if (strlen($day)) $day = "0" . $day;
$sqldate = $year,"-",$month,"-",$day;
that works for getting the server date for today
You could then do
$sql = "select * from tablename where datecolumn='$sqldate'";
etc..
For a set date you could construct the date based on input from drop downs or some type of date math (which is always fun ;)).
[edited by: jatar_k at 1:52 am (utc) on July 8, 2003]
I think I would still store the mysql format but that's just me.
So that would mean that you have to make a range and use a select between. Since the unix timestamp includes the time somewhere in there you can build two timestamps 00:00:01 on given date to 11:59:59 on the same date then use a
for july 8th
$start = mktime [ca.php.net](23,59,59,7,8,2003);
$end = mktime(0,0,1,7,8,2003);
$sql = "select * from tablename where datecolumn between $start and $end";
I think that is right, if you are not using time, just date, then you can set the first 3 params to 0 and select with just the date.