Jump to content


Photo

Date/Time in PHP + MySQL


  • Please log in to reply
1 reply to this topic

#1 mem0ri

mem0ri
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 25 May 2006 - 06:34 PM

The short of the problem:

It doesn't seem (from an inexperienced eye) that there is any easy correlation between the way PHP records and reads time and the way MySQL records and reads time.

My Difficulty:

I want to record times at certain points in my PHP pages and store them in MySQL...in a format that can be read as a date/time and can be re-extracted and adjusted easily by PHP. Example:

--On INSERT to the MySQL database, record the current date and time.
--On query, display the previously recorded date and time in an easily readable format.
--ON UPDATE to the MySQL database, take the previous time and add either x days or x weeks, etc.
--On query...if a certain time has passed...spur another function.

I know they're all essentially easy things to do...I'm just lost...

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 25 May 2006 - 09:26 PM

you can use the PHP time() and date() functions if the dates are not older the 1970.

use time() when you insert the query
to display the time, use date("r", $time) use any format you want instead of the "r" and the $time will be the time you get from the database (the time you recorded).
use mktime() function to update the query with the new time

for details on the functions search for them in [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a]

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users