User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 16 Dec 2002, 14:59   #1
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Date functions in PH & MySQL

Me again

I need to display records of up to a week old, so what I was doing was:

Code:
$today = (date("Ymd") - 7);
...
$query = "SELECT DISTINCT foo1, foo2, foo3 FROM `table` WHERE foo2 > '$today' ORDER BY foo2 ASC";
But then of course, if today was 20021207, then -7 would give 20021200 - which is obviously no help! And of course, today is 20021216, so I was to do - 17 (for example), I'd get 20021199 !

Does anybody have experience of this?

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 16 Dec 2002, 15:06   #2
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
I read a sneaky part of the manual...

Do this:

WHERE TO_DAYS(NOW()) - TO_DAYS(foo2) <= 7 ORDER BY foo2 ASC"

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 16 Dec 2002, 15:30   #3
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Subtracting 604800 from the current timestamp should do it
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 16 Dec 2002, 15:56   #4
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Quote:
Originally posted by Gayle28uk
Subtracting 604800 from the current timestamp should do it
Consider yourself *fwapped*

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 16 Dec 2002, 16:04   #5
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Mong
Consider yourself *fwapped*

M.
???

I hate sounding ignorant but what on Earth is a fwap?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 16 Dec 2002, 18:50   #6
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
http://www.mysql.com/doc/en/Date_and...s.html#IDX1271

in particular you are lookinf for something like

SELECT x,y,z from table WHERE table.date_field > DATE_SUB( CURDATE(), INTERVAL 15 DAY);
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 17 Dec 2002, 10:41   #7
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Cheers MT... but... read the full thread before replying... the answer was already here

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 17 Dec 2002, 21:54   #8
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Originally posted by Mong
Cheers MT... but... read the full thread before replying... the answer was already here

M.
I did read the full thread, but

a) it didnt show how to get to that answer

and

b) I didnt feel that answer was necessarily the best answer.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 18 Dec 2002, 11:49   #9
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
MT: You prefer the "interval" method to the "to_days" method? I guess when dealing with days, there's no difference?

Gayle: To "fwap" is to hit hard, but in a friendly manner

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 18 Dec 2002, 14:43   #10
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Mong
Gayle: To "fwap" is to hit hard, but in a friendly manner

M.
Ah...

My method was still valid though and didn't involve all the buggering about
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 18 Dec 2002, 15:05   #11
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Quote:
Originally posted by Gayle28uk
My method was still valid though and didn't involve all the buggering about
True, true... it just seems to "simple" though :-P

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 18 Dec 2002, 17:41   #12
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Originally posted by Mong
MT: You prefer the "interval" method to the "to_days" method? I guess when dealing with days, there's no difference?
M.
True, theres no difference, but when the next question is "AHA, but what if I want everything that happened up to 8 hours ago", I preferto not have to look thru the manual to find the same page over and over.

Mind you, with these forums liking of 'Mass Prune', archiving threads is pointless anyways :)
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 18 Dec 2002, 18:15   #13
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
I think the INTERVAL method is probably best, actually.

Cheers,

M :smiley1:
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 18 Dec 2002, 19:38   #14
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by MT
True, theres no difference, but when the next question is "AHA, but what if I want everything that happened up to 8 hours ago", I preferto not have to look thru the manual to find the same page over and over.
Time_X_hours_ago = Current_Timestamp - (X*3600)

Expand that equation to include weeks/days/minutes/seconds and you have a generic processor-light way of doint it using nothing more than integer arithmetic. Or do I just like doing things a weird way?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 16:22.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018