0

I want to convert 12/31/2099 to Unix time using PHP. I tried strtotime('12/31/2099') but the function returns null.

I tried converting it to Unix time using an online conversion tool which gives 4102358400 which, when turned into a date gives 01/18/2038.

How can I convert dates to Unix time and again convert it back to a readable format like 12/31/2099?

1
  • as an additional question, what would the number be for 12/31/2099? Commented Jan 4, 2017 at 14:46

3 Answers 3

2

In old versions of PHP ( < 5.1.0), strtotime supported a max date of Tue, 19 Jan 2038 03:14:07 UTC. To bypass this limitation, upgrade to 5.1.0 or later.

64-bit versions are unaffected by this limitation.

For more information, see the Notes: at http://www.php.net/strtotime

Sign up to request clarification or add additional context in comments.

Comments

1

32-bit Unix timestamps run out in 2038, so if you're on a 32-bit system, that would cause a problem.

1 Comment

@Rocket I appreciate the reference.
1

The unix timestamp of a point in time is the number of seconds since 1970-01-01 00:00:00 UTC to this point in time. On 2038-01-18 this will overflow a 32bit signed int - call it the Y2K bug of the unices.

Mind though, that this is a problem of the implementation, not the algotithm: Most current implementations use an unsigned 32bit int, but it is to be expected that 32bit ints will be a thing of the past some time before 2038

Usual workarounds include an if-branch to detect whether a date is after the wraparound and adjust accordingly.

2 Comments

What would be last date or time for 32 bit system?
@RahulSingh: 03:14:07 UTC on Tuesday, 19 January 2038 (en.wikipedia.org/wiki/Year_2038_problem)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.