Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.