PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 17th, 2002, 09:35 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Dates in PHP

ive been thinking of making a small script to handle my things to do for each day, instead of writing them down on paper, and losing it, since i have a bad memory.

i actually havent started the script yet, but theirs this question in the back of my head that ive gotta get out before i start it.

Its about dates in php.

Lets say in a db i have a field inside a table which contains the date the entry was made.

what i want to know is how do i query the db in such a way that todays date, and all days before that, are displayed

im thinking something like this

mysql_query("SELECT * FROM testtable WHERE date <=$todaysdate")

would this work, (the var $todaysdate would equal 2daysday, if you didnt get the idea their)

thanks in advance

Reply With Quote
  #2  
Old April 18th, 2002, 12:06 AM
billsanders billsanders is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Oklahoma, USA
Posts: 13 billsanders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to billsanders
My gut feeling is your example will work, but as a habit, I usually convert all dates to timestamps before doing calculations on them. It may be overkill, but it's kept me out of trouble before.

Reply With Quote
  #3  
Old April 18th, 2002, 04:13 AM
rathaur rathaur is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Malaysia
Posts: 82 rathaur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 57 sec
Reputation Power: 16
Me too, sore the time in timestamp , and with PHP functions, its easily convertable to other formats
__________________
Rathaur
======================
Knowledge is Power

Reply With Quote
  #4  
Old April 18th, 2002, 07:47 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
what exactly is a timestamp??? to get the time i just use gmtime()??

is their a better way?? can you please explain about his timestamp

thanks

Reply With Quote
  #5  
Old April 18th, 2002, 08:32 AM
partyganger partyganger is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Limmen
Posts: 16 partyganger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
a time stamp is the number of seconds or milliseconds passed since the Unix Epoch (1-1-1970). Best would be if you insert a date using PHP with (for example):
Code:
$query = "insert into timetable values(date('Y-m-d'))";


or something like that...

Reply With Quote
  #6  
Old April 18th, 2002, 09:39 AM
billsanders billsanders is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Oklahoma, USA
Posts: 13 billsanders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to billsanders
For instance, when you store the date in your MySQL database, you might do it like so:

mysql_query("INSERT INTO testtable SET date=CURDATE(), task='What to do today'");

This, of course, inserts the current date in the "date" column. Then, as you suggested in your initial question, you SHOULD be able to retrieve the data thus:

$result=mysql_query("SELECT * FROM testtable WHERE date<=CURDATE() AND task IS NOT NULL");

I haven't tested it, but it should work.

An alternative uses timestamps. Consider (in PHP):

$date = time();
$task = "What to do today";
mysql_query('INSERT INTO testtable SET date="$date", task="$task"');

Then, to retrieve your list, you could use:

$date = time();
$result=mysql_query('SELECT * FROM testtable WHERE date<="$date" AND task IS NOT NULL');
while ($answer = mysql_fetch_array($result)) {
$timestamp=$answer['date'];
$fdate=date("D M j, Y",$timestamp);
echo "Date: ".$fdate." Task: ".$answer['task']."<br>\n";
}

Again, this method could be overkill. Your original choice is more elegant if it works.

Reply With Quote
  #7  
Old April 25th, 2002, 09:01 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
thanks for your suggestions guys, ill start programing it soon, and let you know how it goes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Dates in PHP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap