Reputation: 107
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.
Upvotes: 1
Views: 98
Reputation: 5894
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"...
Upvotes: 1