Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date in shop cart db

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
how can I delete all fields from a database that are older than 2 days Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
I have a date field in my row Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
the simplest way is to determine the format of youre datefield and then:

delete from table where (select date from table where date < date('d-m-y', time() - 24 * 3600 * 2));

in php. mcvdmvs
&quot;It never hurts to help&quot; -- Eek the Cat
 
this is my query ;

Code:
$query = &quot;DELETE FROM session WHERE (SELECT date FROM session WHERE date < date('Y-j-m', mktime(date('j')-2)))&quot;;

But it dosn't work any ideas? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
of course it doesn't work. The call to the PHP function is INSIDE the string.

$query = &quot;DELETE FROM session WHERE (SELECT date FROM session WHERE date < '&quot;.date('Y-j-m', mktime(date('j')-2))).&quot;'&quot;;

This can work. But i didn't tested. I don't use mysql for one year, so i don't remember anything.


Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
oops of course silly me Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
I changed it to this but it still won't work

$query = &quot;DELETE FROM session WHERE (SELECT date FROM session WHERE date < &quot; . date(&quot;Y-m-d&quot;, mktime(date(&quot;d&quot;)-2)) . &quot;)&quot;; Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
as i told you, i don't use mysql. I can't help you more than this.

But just a thing, usualy the date fields are with trailing zeros, so, instead of using 'j' change to 'd'

As i remember, the date format in mysql is 'yyyy-mm-dd'. But i'm not sure. I'm used only to Sql Server and Oracle. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top