1

Alright, So i'm currently working on a game of sorts and I've hit a small snag in that -- up until about an hour ago, the time in the game was working off the datetime function built into PHP, but that's sorta stopped working, because the 2038 time bug.

I'm trying to work around it by making my own time system, which is slowly becoming a pain in the ass. (Because i'm not 100% sure what i'm doing)

I've got this code here

echo "TIME:".$time.'<br/>';
$year = ceil($time/GYEAR);
if($year%GMONTH) { $month = ceil($year/GMONTH);}else{ $month = '';}
if($month%GDAY) { $day = ceil($month/GDAY); } else { $day = '';}

echo $year.'-'.$month.'-'.$day;

Which is supposed to be the basis of my Time system, but I'm doing something wrong and can only properly get the year, not the month or day.

The constants are

    define("GMIN", 60);
    define("GHOUR", GMIN*60);
    define("GDAY", GHOUR*24);
    define("GMONTH", GDAY*30);
    define("GYEAR", GMONTH*12);
   define("TIME_STEP", GMONTH*12+GDAY);`

the time variable is just TIME_STEP * however many times i've run it (It's stored in the DB, right now it's value is: 1736899200)

I'm pretty sure the issue is i'm not certain how to use the % operator, but i'd likke some input on this.

  • The 2038 bug is something that happened on 32bit OS. Don't use this as a server please. Take a good server on x64, that'll support your timestamp without having to hack them... – Blag Feb 15 '16 at 02:22
  • @Blag I have x64 system but every time i get to 2038 in a timestamp it is reset to 0000-00-00 00:00:00 – Patrick Pierson Feb 15 '16 at 02:24
  • http://stackoverflow.com/questions/5319710/accessing-dates-in-php-beyond-2038 may be related I think. As it seem that the 2038 bug is not really patched for now even with x64 – Blag Feb 15 '16 at 02:27

1 Answers1

1

Best way for me is to use the php DateTime class and the MySql DateTime field.

They both support date over 2038 and will be better to use than you own custom "thing"...

Blag
  • 5,818
  • 2
  • 22
  • 45
  • Huh, does the TimeStamp field NOT support it? i'm looking at my structure, it was set to TimeStamp not DateTime – Patrick Pierson Feb 15 '16 at 02:33
  • @PatrickPierson mysql timestamp use a INT storage `the range for TIMESTAMP values is '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'.` The dateTime one can take Y1000 to Y9999 – Blag Feb 15 '16 at 02:36
  • Alright, that must've been the issue. i'm giving it a whirl now, thank you @Blag – Patrick Pierson Feb 15 '16 at 02:38
  • @PatrickPierson you"re welcome ;) this is related to http://stackoverflow.com/questions/2012589/php-mysql-year-2038-bug-what-is-it-how-to-solve-it and explain a bit more – Blag Feb 15 '16 at 02:40