MySQL - bigints and php

Go To StackoverFlow.com

1

How do I cope with a bigint (milliseconds since 1970) got from a mysql table, when the max int size in php is a lot lower than this for current dates and times.

2012-04-04 21:45
by Rewind


3

You can either

  1. Divide by 1000 and use a float (with optional use of arbitrary precision maths functions to do any calculation on them (outside of <, = or >))
  2. Store as a string (and not do any calculations)
  3. Upgrade to a 64-bit OS and re-install PHP (much larger MAXINT value)
2012-04-04 22:37
by DaveyBoy
Thanks for the answers guys. Both mention the /1000, but a year is 31536000 seconds, so I think its about 2038 when things get dodgy - Rewind 2012-04-05 10:06
Thanks for the answers guys. Both mention the /1000, which is what I am likely going to do, but I do like the string idea. As for the /1000 a year is 31536000 seconds, so I think its about 2038 when things get dodgy. I have seen some weird behaviour regarding bigints and have started a new thread. I have marked DaveyBoy as the answer as he also mentioned the string idea - Rewind 2012-04-05 10:12


3

PHP's max int size is plenty big on a 64 bit architecture. What are you running it on? Other ideas include:

  1. Divide result by 1000 and cast to integer in MySQL, eg, SELECT CAST(ts/1000 AS INT) AS ts
  2. Convert to a float when received in PHP (less accuracy)
2012-04-04 21:47
by gahooa
Ads