LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2023, 04:27 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Angry Any PHP wizards here? I am trying to figure out if PHP's built in time() and mktime() functions can understand dates beyond 2038?


I've read some things that says on a 64bit machine and 64bit PHP it should be fine to go beyond the 32bit signed barrier, of which my VM meets both criteria (as far as I can tell) and yet my script just halts as soon as I try to get the unix_ts of a 2038 date.

Any tips?
 
Old 05-29-2023, 05:55 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,678

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
What is the output of this php CLI program? Include shebang and php tags etc...
Code:
$date = '2040-02-01';
$format = 'l d F Y H:i';
$mydate1 = strtotime($date);
echo "date = $date\n";
echo "Feb 1, 2040 is on a " . date("l", mktime(0, 0, 0, 2, 1, 2040))."\n";
echo "Unix timestamp  = $mydate1\n";
echo "$mydate1 time stamp = ".date("$format",$mydate1)."\n";
 
1 members found this post helpful.
Old 05-29-2023, 07:10 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by michaelk View Post
What is the output of this php CLI program? Include shebang and php tags etc...
Code:
$date = '2040-02-01';
$format = 'l d F Y H:i';
$mydate1 = strtotime($date);
echo "date = $date\n";
echo "Feb 1, 2040 is on a " . date("l", mktime(0, 0, 0, 2, 1, 2040))."\n";
echo "Unix timestamp  = $mydate1\n";
echo "$mydate1 time stamp = ".date("$format",$mydate1)."\n";
Code:
date = 2040-02-01
Feb 1, 2040 is on a Wednesday
Unix timestamp  = 2211696000
2211696000 time stamp = Wednesday 01 February 2040 00:00
Huh, I guess that works. I'll have to go figure out why my code is not working then.

Last edited by wh33t; 05-29-2023 at 07:12 PM.
 
Old 05-29-2023, 07:13 PM   #4
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Ahh. I'm trying to ram this giant number into a mysql (int), I guess it needs to be a double?

Nope, wrong again, it needs to be a bigint!

Thanks for your help!

Last edited by wh33t; 05-29-2023 at 07:18 PM.
 
Old 05-29-2023, 07:44 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,678

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
mysql signed integers are +/- 2147483647 (January 19, 2038) but unsigned is 0 - 4294967295 (February 7, 2106)
Integers use 4 bytes of storage whereas bigint use 8 bytes of storage if anyone cares...
 
1 members found this post helpful.
Old 06-07-2023, 07:56 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Instead of using any sort of "int," you should be using MySQL's provided date or datetime column types. Tell MySQL that the data being stored "is what it really is," and it will happily do the heavy lifting for you.
 
Old 06-07-2023, 08:01 PM   #7
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by sundialsvcs View Post
Instead of using any sort of "int," you should be using MySQL's provided date or datetime column types. Tell MySQL that the data being stored "is what it really is," and it will happily do the heavy lifting for you.
I know it's an option. I prefer unix timestamps though.

Thanks for the advice though.
 
Old 06-08-2023, 12:47 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
For which you'd use https://www.w3resource.com/mysql/dat...p-function.php .

As per sundialsvcs, use one of the "date types" cols for actual date storage https://dev.mysql.com/doc/refman/8.0/en/datetime.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] php: mktime switcher51 Programming 2 02-17-2015 05:44 PM
LXer: On dates and stuffed non-dates LXer Syndicated Linux News 0 10-08-2014 02:21 AM
awk and strftime/mktime - characters added to end of date/time conversion string jonbob75 Programming 3 10-07-2013 08:59 AM
[SOLVED] generate dates between two dates ip_address Programming 4 03-21-2013 04:28 PM
Trying to figure out/understand this BIND/DNS thing MasterC Linux - Networking 11 09-21-2003 02:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration