|
16 Dec 2002, 14:59
|
#1
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
16 Dec 2002, 15:06
|
#2
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
16 Dec 2002, 15:30
|
#3
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
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!!!
|
|
|
16 Dec 2002, 15:56
|
#4
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
16 Dec 2002, 16:04
|
#5
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
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!!!
|
|
|
16 Dec 2002, 18:50
|
#6
|
/dev/zero Retired Mod
Join Date: May 2000
Posts: 415
|
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
|
|
|
17 Dec 2002, 10:41
|
#7
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
17 Dec 2002, 21:54
|
#8
|
/dev/zero Retired Mod
Join Date: May 2000
Posts: 415
|
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
|
|
|
18 Dec 2002, 11:49
|
#9
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
18 Dec 2002, 14:43
|
#10
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
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!!!
|
|
|
18 Dec 2002, 15:05
|
#11
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
18 Dec 2002, 17:41
|
#12
|
/dev/zero Retired Mod
Join Date: May 2000
Posts: 415
|
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
|
|
|
18 Dec 2002, 18:15
|
#13
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
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"
|
|
|
18 Dec 2002, 19:38
|
#14
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
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!!!
|
|
|
|
All times are GMT +1. The time now is 17:26.
| |