Closed Thread Icon

Preserved Topic: calculate one week ago from unix time stamp? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21047" title="Pages that link to Preserved Topic: calculate one week ago from unix time stamp? (Page 1 of 1)" rel="nofollow" >Preserved Topic: calculate one week ago from unix time stamp? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 01-08-2002 04:23

I have an idea....

let's say I have a ton of records in a MySQL database, each one of which has a date stamp in the usual
yyyy-mm-dd format. I'd like to grab all the records from, say, the last week via PHP/MySQL. Would mktime in PHP be the best way to do it?



[This message has been edited by Pugzly (edited 01-08-2002).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-08-2002 05:46

Question: Is the date stored as a DATE datatype or just date info in some sort of text datatype

If it's an actually a date datatype you should be able to use the DATE_SUB() MySQL funtion to retrieve this.

SELECT * FROM datatable WHERE datefield > DATE_SUB(NOW(), INTERVAL 7 DAY)

Should work gotta give it a try though.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-08-2002 12:09

oh, and mysql even has an alternative syntax for this, at least in the newer versions:
select * from yourtable where date >= (CURRENT_TIMESTAMP - interval 7 DAYS);

I don't know how standards conform it is, tough.

so long,
Tyberius Prime

Edit: gave you all records that were older than a week.

[This message has been edited by Tyberius Prime (edited 01-08-2002).]

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 01-08-2002 16:29

Ya know, now that I read this, this stuff does ring a bell.... I must be getting old.

Thanks - I'll try these.

« BackwardsOnwards »

Show Forum Drop Down Menu