[advanced search]
Results from the most recent live auction are here.
19 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 10-12-2003, 02:47 PM   · #1
web guru
NamePros Member
 
Trader Rating: (0)
Join Date: Jul 2003
Posts: 120
NP$: 185.00 (Donate)
web guru is an unknown quantity at this point
mySQL timestamp(14)

I am trying to find the difference between the current date and and the date each record was created in my database. I have used a field called date in my database of type timestamp(14) which automatically inserts the date and time the recorde was created.

Now how do I get the diff??


Please register or log-in into NamePros to hide ads
web guru is offline   Reply With Quote
Old 10-13-2003, 01:59 AM   · #2
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
That's a tough one. If you could get the date values in the format of yyyymm or yymm then you could easily get the difference in months and years with mysql's period_diff() function. Something like this:

$result = mysql_fetch_array(mysql_query("select period_diff(200309,199909) as diff;"));

That would give you the difference in months and then you could calculate the years with something like:
$yearsdif = $result['dif'] / 12;

Some pages that may or not help you:
http://www.faqts.com/knowledge_base...id/12241/fid/15

http://www.mysql.com/doc/en/Date_an..._functions.html

http://us3.php.net/manual/en/ref.datetime.php
deadserious is offline   Reply With Quote
Old 10-13-2003, 02:10 AM   · #3
web guru
NamePros Member
 
Trader Rating: (0)
Join Date: Jul 2003
Posts: 120
NP$: 185.00 (Donate)
web guru is an unknown quantity at this point
I was trying to figure this out all last night and I finally cracked it. I was trying to find the difference using php, but it was proving difficult because, well lets just say it was to dam awkward. So I found that it was easier done using SQL, like the way you did it dead. The following peace of SQL checks the database and any records that are over five days old are deleted.

Code:
mysql_query("DELETE FROM pass WHERE TO_DAYS(NOW()) - TO_DAYS(date) > 5;")


I am going to run this as a cron job every night so that old entries are deleted out of my database.
web guru is offline   Reply With Quote
Old 10-13-2003, 02:59 AM   · #4
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
Cool, atleast you figured out something that works for what you wanted.

I wonder what you're doing though, deleting users after five days or just their password or? Just curious.
deadserious is offline   Reply With Quote
Old 10-13-2003, 03:54 AM   · #5
web guru
NamePros Member
 
Trader Rating: (0)
Join Date: Jul 2003
Posts: 120
NP$: 185.00 (Donate)
web guru is an unknown quantity at this point
I am deleting users after five days, as they have up to five days to access the site and download the product that they have paid for.
web guru is offline   Reply With Quote
Old 10-20-2003, 07:57 PM   · #6
antoshka
New Member
 
Trader Rating: (0)
Join Date: Oct 2003
Posts: 4
NP$: 7.00 (Donate)
antoshka is an unknown quantity at this point
it is always better to store timestamps as int(11). it fits and there's less confusion
antoshka is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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
Forum Jump


Site Sponsors
Buy Flash Arcade Game Script YUPPADS Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 09:18 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0