-1

I am working for this association in my school and I am migrating web applications since, as of today, they are still running in PHP 4.4... But, I would like to quickly implement some fixes before changing to a newer PHP version.

One of these changes is related to dates comparison. The problem is I don't have strtotime and stuff like that, they all came in PHP 5.x.

I have to check if a timestamp is in one of two time intervals. In concrete: I have a timestamp for when a person adhered to the association, school year goes from September 1st of year N to July 31st of year N+1, and I must check if the timestamp (and also the current time) lies

  • Between September 1st of year N and January 31st of year N+1, or
  • Between January 1st of year N+1 and July 31st of year N+1

So the question is what is the best way to do this? I came up with a solution: create my own timestamps and then compare. To create a timestamp for year N, I multiply the number of years since epoch time (N - 1970) by the number of seconds in a year ( 365.25 * 24 * 60 * 60 ). Then to that timestamp I add the number of seconds to September 1st, to January 1st, and so on. Finally I compare the whole. Isn't there a better way?

C. Miranda
  • 75
  • 1
  • 6
  • 4
    Whaaat, PHP 4?! Released over 17 years ago (PHP 4.4 in 2005)! Sounds like your school is stuck in the past. It's an interesting problem though. You can still create your own function that converts a timestamp to a date though. – Qirel Aug 25 '17 at 23:09
  • is it that the PHP doesn't have `strtotime` or that the school for some wyrdo reason have disabled this function for you to use? Can you clarify that you absolutely can't access the result of the `strtotime` function? – Martin Aug 25 '17 at 23:32
  • PHP 4.4 has been [End Of Life for 9 years](http://php.net/eol.php). So you should assume you've been hacked, or will be soon. – Machavity Aug 25 '17 at 23:43
  • I cannot think of any *sane* reason to be running PHP 4 at this point in time. You have *far larger problems* than missing a few functions. – Sammitch Aug 25 '17 at 23:54

1 Answers1

2

You are able to use PHP's strtotime function in PHP 4.4: http://php.net/manual/en/function.strtotime.php

strtotime

(PHP 4, PHP 5, PHP 7)

strtotime — Parse about any English textual datetime description into a Unix timestamp

Here is an online example where you can run strtotime in 4.4.9: http://sandbox.onlinephpfunctions.com/code/38559a58820d08105f746691bf338c565c1ed4e0

Mike S
  • 1,636
  • 7
  • 11