| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Jul 2003
Posts: 118
![]() | 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??
__________________ Paulicon Web design - Your one stop shop |
| |
| | #2 (permalink) |
| Senior Member Join Date: Aug 2002
Posts: 1,255
![]() ![]() | 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: ????: NamePros.com http://www.namepros.com/programming/15371-mysql-timestamp-14-a.html $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/...d/12241/fid/15 http://www.mysql.com/doc/en/Date_and...functions.html http://us3.php.net/manual/en/ref.datetime.php |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Member Join Date: Jul 2003
Posts: 118
![]() | 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. ????: NamePros.com http://www.namepros.com/showthread.php?t=15371 Code: mysql_query("DELETE FROM pass WHERE TO_DAYS(NOW()) - TO_DAYS(date) > 5;")
__________________ Paulicon Web design - Your one stop shop |
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Member Join Date: Jul 2003
Posts: 118
![]() | 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.
__________________ Paulicon Web design - Your one stop shop |
| |
| | #6 (permalink) |
| New Member Join Date: Oct 2003
Posts: 4
![]() | it is always better to store timestamps as int(11). it fits and there's less confusion
__________________ $1.95 Web Hosting - RouTHost.com |
| |