SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <?php echo date('d-M-Y',strtotime('19-06-2038')); ?> output is wrong..,

    To format date, I am using following line of code...
    PHP Code:
    <?php echo date('d-M-Y',strtotime('19-06-1983')); ?>
    but if I enter date with year 2038 or above(like below), it displays '01-Jan-1970'....

    this might be due to the limit of strtotime() function. How can I overcome this problem.
    [COLOR=SlateGray]
    Web Developer @ VeriQual

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is due to unix time being seconds based, you'd need a 64-bit system to go past ~2038. How come you're using 2038?
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The fact that the unix time stamp is limited to such a small date range annoys me, and php basing all it's date functionality on this seriously limited method as well.

    I wrote my own date class to get around this :P

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know if there any plans to address this?

    It seems quite a major issue TBH, not that 2038 is round the corner...

    Surely there are applications that would look to use dates as far forward as these.

    No?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yeh, or before 1970, especially for birth dates.

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    Yeh, or before 1970, especially for birth dates.
    Before 1970 you can always use negative values.

  7. #7
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can, which will take you back as far as 1901. For storing anything before that (historical dates etc), you are still screwed. 137 years is still a very low range for date storage.

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHPs datetime class can handle a far wider range of dates.
    I've not tried checking the limits because it's a pig to work with, and I have no real need for such a wide range of dates... but it's own built-in strtotime functionality does handle both '/' and '-' as date separators, which is useful.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  9. #9
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mark Baker View Post
    PHPs datetime class can handle a far wider range of dates. I've not tried checking the limits
    From a very quick look, DateTime appears not to have any problems with years covering the integer range (32 bit system; -21474836472147483647).
    Salathe
    Software Developer and PHP Manual Author.

  10. #10
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    just as a matter of interest does strtotime('19-06-1983') work ok? that's how uk and presumably a number of other countries commonly write dates (day, month, year) but in the u.s. it's month, day, year i'm pretty sure. so how is php supposed to know which you're using? it's impossible. ok in that particular example it can't be the u.s. way because there are not 19 months but that's just lucky. 1983-06-19 is i assume the only safe way to write that.

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Does anyone know if there any plans to address this?

    It seems quite a major issue TBH, not that 2038 is round the corner...

    Surely there are applications that would look to use dates as far forward as these.

    No?
    The switch from 32 bit to 64 bit computers takes care of it automatically since each additional bit doubles the time period that can be covered and so even with the first 30 bits of a 64 bit field still zero a 548 year period is covered. With all 64 bits a period of 588410 million years is covered. That should be enough for the forseeable future.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Considering that 30-year mortgages started needing date support past 2038 this year, it would probably be a good idea for PHP to work in some kind of patch that works on 32-bit systems.

  13. #13
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The switch from 32 bit to 64 bit computers takes care of it automatically
    If that ever happens! It's being very slow :/

  14. #14
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The switch from 32 bit to 64 bit computers takes care of it automatically
    If only it was that simple! There are still hosts on PHP4 out there, and to be fair, it's not the exception to the rule.

    I'm sure they'll be on PHP6 before they're on 64bit.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •