Jump to content

Date/Time in PHP + MySQL


mem0ri

Recommended Posts

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...
Link to comment
https://forums.phpfreaks.com/topic/10453-datetime-in-php-mysql/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/10453-datetime-in-php-mysql/#findComment-39016
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.