Re: Formatting Date (m/d/yyyy) To Timestamp
| From: | Sam Hobbs | Date: | Tue, 12 Jan 2021 03:37:14 +0000 |
| Subject: | Re: Formatting Date (m/d/yyyy) To Timestamp | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327407@lists.php.net to get a copy of this message | ||
I am not a PHP expert. I have been programming in other languages for about half a century.
I assume you want to do the conversion using PHP, not SQL.
I had forgotten what a UNIX timestamp is but I see that it is defined as the number of seconds since January 1st, 1970 at UTC.
When I look at PHP: Date and Time Related Extensions - Manual <https://www.php.net/manual/en/refs.calendar.php> I find the DateInterval <https://www.php.net/manual/en/class.dateinterval.php> class. It can be used to determine the number of seconds between two dates. Can you convert the specified dates to DateTime <https://www.php.net/manual/en/class.datetime.php>objects?
Since the UNIX timestamp is the number of seconds since January 1st, 1970 at UTC, the difference between January 1st, 1970 at UTC and a specified date is the amount of time since January 1st, 1970 at UTC and that difference in seconds is the UNIX timestamp. Right?
Something to look closely at is what precise time to use. Is the timestamp supposed to be for the first second or the last second of a specified day?
Talin Sharma wrote on 1/10/2021 3:17 PM:
Hi All, I have a string: '1/1/2021'. I want to turn this into a timestamp for entering into MySql. I have tried everything I could find. Please let me know how to proceed. Also, let me know if you need more information. Thanks:Talin Sharma