Click to See Complete Forum and Search --> : Date Retreval from MySQL
windriderme
05-23-2005, 11:38 AM
I am working on a unique calender script. I have every thing working the way I want it except 1 thing. I am having issues seting up the sql statement to retreive the date from the database so I can display it in my table. My psuedo code looks like this:
$timestamp = mktime(0,0,0, date("m") , date("d"), date("Y"));
SELECT 'time', 'eventname' FROM 'calendar' WHERE 'date' = $timestamp
What I need to find is a way to convert the $timestamp into something the database can compare to the date format it is using (YYYY-mm-dd) or determine what a better sql type would be beside the DATE type. Which ever solution will be easiest is what I would prefer. Any help I could get would be appreciated. Thanks in advance!
BeachSide
05-23-2005, 12:16 PM
Scroll down about 7 or 8 posts and you will find this...
http://www.webdeveloper.com/forum/showthread.php?t=66873
NogDog
05-23-2005, 01:44 PM
I think this is what you're looking for?
$today = date("Y-m-d"); # yyyy-mm-dd format
$query = "SELECT `time`, `eventname` FROM `calendar` WHERE `date` = '$timestamp'";
windriderme
05-23-2005, 02:15 PM
That bit of code will work for one day, yes. But what I am doing is a calender with 7 days. Currently I have the $timestamp repaeted 7 times adding a day each time and this is working great. I have other variables that I am pulling from the $timestamp as well so I really need to use that if possible or if you could help me figure out how to increment your variable $today by 1 then that would work. I tried this method before however (just trying to get it to increment by 1) and could not figure it out.
NogDog
05-23-2005, 05:32 PM
Well, you could increment it this way:
for($day=0; $day<7; $day++)
{
$today = date("Y-m-d", time()+$day*60*60*24);
# do stuff with $today
}
windriderme
05-23-2005, 06:17 PM
I'll admit this is closer because it allows the incrementing. the problem is that it does it all on its own without seperating the results. This is a calender which means that I need to have the results seperated into seperate areas. even if I ran this and it pulled all the events listed for the 7 day period it calculated there is no way to seperate those results and put them in a calendar format. I would prefer to work with the $timestamp becase it is a variable I already have and am using for several other variables which $time would not.
NogDog
05-23-2005, 08:36 PM
Maybe...
$timestamp = mktime(0,0,0, date("m") , date("d"), date("Y"));
$query = "SELECT `time`, `eventname` FROM `calendar` " .
"WHERE `date` = FROM_UNIXTIME($timestamp, '%Y-%m-%d')";