mktime() and UNIXTIME epoch.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandman

    mktime() and UNIXTIME epoch.

    Hi.

    On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with PHP.
    That is, when feeding a function that turns dfates into unixtime, such as
    mktime() and strtotime()

    print date("Y-m-d", mktime(0,0,0,1, 1,1930));
    -> "1969-12-31" (since the result of mktime is "-1")

    But date() gets it though, so if I do

    print date("Y-m-d", -1000000000);
    -> "1938-04-24"

    Now, presumably this has something to do with Linux instead of PHP, since doing
    this in MySQL doesn't work either:

    select unix_timestamp( '1935-12-03');
    -> 0

    But, when using perl, it works just fine when using Date::Manip:

    #!/usr/bin/perl
    use Date::Manip;
    $date = UnixDate("1945-01-23", "%s");
    print $date;
    -> -787021200

    So, how come MySQL can't do it, PHP can't do it, but somehow perl can? Can I
    compile PHP with negative integer date support?

    --
    Sandman[.net]
  • Jochen Daum

    #2
    Re: mktime() and UNIXTIME epoch.

    Hi Sandman!

    On Wed, 18 Feb 2004 09:59:52 +0100, Sandman <mr@sandman.net > wrote:
    [color=blue]
    >Hi.
    >
    >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with PHP.
    >That is, when feeding a function that turns dfates into unixtime, such as
    >mktime() and strtotime()
    >
    > print date("Y-m-d", mktime(0,0,0,1, 1,1930));
    > -> "1969-12-31" (since the result of mktime is "-1")
    >
    >But date() gets it though, so if I do
    >
    > print date("Y-m-d", -1000000000);
    > -> "1938-04-24"
    >
    >Now, presumably this has something to do with Linux instead of PHP, since doing
    >this in MySQL doesn't work either:
    >
    > select unix_timestamp( '1935-12-03');
    > -> 0
    >
    >But, when using perl, it works just fine when using Date::Manip:
    >
    > #!/usr/bin/perl
    > use Date::Manip;
    > $date = UnixDate("1945-01-23", "%s");
    > print $date;
    > -> -787021200
    >
    >So, how come MySQL can't do it, PHP can't do it, but somehow perl can? Can I
    >compile PHP with negative integer date support?[/color]

    I think it depends on the underlying unix libraries. I think a better
    approach would IMO to write a library based on the MySQL date
    functions (or any other database), which should support date support
    from 1908-xxxx or earlier. The SQL-92 functions ar much more
    rudimentary than what PHP offers, but with some regexes you should get
    something going. For dates before 1908 you should ask anyway "Where?",
    I was amazed reading Joe Celko's "SQL for Smarties"

    HTH, Jochen


    Comment

    • Sandman

      #3
      Re: mktime() and UNIXTIME epoch.

      In article <jec630tuq7rjci gjmd0572jjot1hu 76ons@4ax.com>,
      Jochen Daum <jd@jdaum.de> wrote:
      [color=blue][color=green]
      > >Hi.
      > >
      > >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with
      > >PHP. That is, when feeding a function that turns dfates into unixtime, such
      > >as mktime() and strtotime()
      > >
      > > print date("Y-m-d", mktime(0,0,0,1, 1,1930));
      > > -> "1969-12-31" (since the result of mktime is "-1")
      > >
      > >But date() gets it though, so if I do
      > >
      > > print date("Y-m-d", -1000000000);
      > > -> "1938-04-24"
      > >
      > >Now, presumably this has something to do with Linux instead of PHP, since
      > >doing this in MySQL doesn't work either:
      > >
      > > select unix_timestamp( '1935-12-03');
      > > -> 0
      > >
      > >But, when using perl, it works just fine when using Date::Manip:
      > >
      > > #!/usr/bin/perl
      > > use Date::Manip; $date = UnixDate("1945-01-23", "%s"); print $date;
      > > -> -787021200
      > >
      > >So, how come MySQL can't do it, PHP can't do it, but somehow perl can? Can
      > >I compile PHP with negative integer date support?[/color]
      >
      > I think it depends on the underlying unix libraries. I think a better
      > approach would IMO to write a library based on the MySQL date functions (or
      > any other database), which should support date support from 1908-xxxx or
      > earlier.[/color]

      Eh, I don't understand... Are you recommending I use MySQL to obtain dates
      earlier than 1970 even though I showed above that MySQL doesn't support it
      either...? I am confused.

      To recap again. MySQL doesn't support it, PHP doesn't support it, Perl supports
      it.

      --
      Sandman[.net]

      Comment

      • Jochen Daum

        #4
        Re: mktime() and UNIXTIME epoch.

        Hi Sandman!

        On Wed, 18 Feb 2004 10:51:08 +0100, Sandman <mr@sandman.net > wrote:
        [color=blue]
        >In article <jec630tuq7rjci gjmd0572jjot1hu 76ons@4ax.com>,
        > Jochen Daum <jd@jdaum.de> wrote:
        >[color=green][color=darkred]
        >> >Hi.
        >> >
        >> >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with
        >> >PHP. That is, when feeding a function that turns dfates into unixtime, such
        >> >as mktime() and strtotime()
        >> >
        >> > print date("Y-m-d", mktime(0,0,0,1, 1,1930));
        >> > -> "1969-12-31" (since the result of mktime is "-1")
        >> >
        >> >But date() gets it though, so if I do
        >> >
        >> > print date("Y-m-d", -1000000000);
        >> > -> "1938-04-24"
        >> >
        >> >Now, presumably this has something to do with Linux instead of PHP, since
        >> >doing this in MySQL doesn't work either:
        >> >
        >> > select unix_timestamp( '1935-12-03');
        >> > -> 0
        >> >
        >> >But, when using perl, it works just fine when using Date::Manip:
        >> >
        >> > #!/usr/bin/perl
        >> > use Date::Manip; $date = UnixDate("1945-01-23", "%s"); print $date;
        >> > -> -787021200
        >> >
        >> >So, how come MySQL can't do it, PHP can't do it, but somehow perl can? Can
        >> >I compile PHP with negative integer date support?[/color]
        >>
        >> I think it depends on the underlying unix libraries. I think a better
        >> approach would IMO to write a library based on the MySQL date functions (or
        >> any other database), which should support date support from 1908-xxxx or
        >> earlier.[/color]
        >
        >Eh, I don't understand... Are you recommending I use MySQL to obtain dates
        >earlier than 1970 even though I showed above that MySQL doesn't support it
        >either...? I am confused.
        >
        >To recap again. MySQL doesn't support it, PHP doesn't support it, Perl supports
        >it.[/color]

        If you look at


        and just do not use any %UNIX% functions, you should be fine. I just
        tested

        SELECT INTERVAL 1 DAY + '1925-12-31'

        and its New Years day 1926.

        HTH, Jochen



        Comment

        • Sandman

          #5
          Re: mktime() and UNIXTIME epoch.

          In article <5hd630liph63pc 5105l7r0ok0n70v iphhq@4ax.com>,
          Jochen Daum <jd@jdaum.de> wrote:
          [color=blue][color=green][color=darkred]
          > >> >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with
          > >> >PHP. That is, when feeding a function that turns dfates into unixtime,
          > >> >such as mktime() and strtotime()
          > >> >
          > >> > print date("Y-m-d", mktime(0,0,0,1, 1,1930));
          > >> > -> "1969-12-31" (since the result of mktime is "-1")
          > >> >
          > >> >But date() gets it though, so if I do
          > >> >
          > >> > print date("Y-m-d", -1000000000);
          > >> > -> "1938-04-24"
          > >> >
          > >> >Now, presumably this has something to do with Linux instead of PHP,
          > >> >since doing this in MySQL doesn't work either:
          > >> >
          > >> > select unix_timestamp( '1935-12-03');
          > >> > -> 0
          > >> >
          > >> >But, when using perl, it works just fine when using Date::Manip:
          > >> >
          > >> > #!/usr/bin/perl
          > >> > use Date::Manip; $date = UnixDate("1945-01-23", "%s"); print $date;
          > >> > -> -787021200
          > >> >
          > >> >So, how come MySQL can't do it, PHP can't do it, but somehow perl can?
          > >> >Can I compile PHP with negative integer date support?
          > >>
          > >> I think it depends on the underlying unix libraries. I think a better
          > >> approach would IMO to write a library based on the MySQL date functions
          > >> (or any other database), which should support date support from 1908-xxxx
          > >> or earlier.[/color]
          > >
          > >Eh, I don't understand... Are you recommending I use MySQL to obtain dates
          > >earlier than 1970 even though I showed above that MySQL doesn't support it
          > >either...? I am confused.
          > >
          > >To recap again. MySQL doesn't support it, PHP doesn't support it, Perl
          > >supports it.[/color]
          >
          > If you look at http://www.mysql.com/doc/en/Date_and...functions.html
          >
          > and just do not use any %UNIX% functions, you should be fine. I just tested
          >
          > SELECT INTERVAL 1 DAY + '1925-12-31'
          >
          > and its New Years day 1926.[/color]

          I realize that - but perhaps I was unclear at what I wanted. I WANT the unix
          timestamp of a given date.

          select unix_timestamp( "1985-01-01");
          -> 473382000

          select unix_timestamp( "1925-01-01");
          -> 0

          What that other select SHOULD return is "-1420074000" and THAT's what I want. I
          want a function, prefferably in PHP, that will return "-1420074000" when I feed
          it with "1925-01-01".

          --
          Sandman[.net]

          Comment

          • Jochen Daum

            #6
            Re: mktime() and UNIXTIME epoch.

            Hi Sandman!

            On Wed, 18 Feb 2004 12:00:19 +0100, Sandman <mr@sandman.net > wrote:
            [color=blue]
            >In article <5hd630liph63pc 5105l7r0ok0n70v iphhq@4ax.com>,
            > Jochen Daum <jd@jdaum.de> wrote:
            >[color=green][color=darkred]
            >> >> >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with
            >> >> >PHP. That is, when feeding a function that turns dfates into unixtime,
            >> >> >such as mktime() and strtotime()
            >> >> >
            >> >> > print date("Y-m-d", mktime(0,0,0,1, 1,1930));
            >> >> > -> "1969-12-31" (since the result of mktime is "-1")
            >> >> >
            >> >> >But date() gets it though, so if I do
            >> >> >
            >> >> > print date("Y-m-d", -1000000000);
            >> >> > -> "1938-04-24"
            >> >> >
            >> >> >Now, presumably this has something to do with Linux instead of PHP,
            >> >> >since doing this in MySQL doesn't work either:
            >> >> >
            >> >> > select unix_timestamp( '1935-12-03');
            >> >> > -> 0
            >> >> >
            >> >> >But, when using perl, it works just fine when using Date::Manip:
            >> >> >
            >> >> > #!/usr/bin/perl
            >> >> > use Date::Manip; $date = UnixDate("1945-01-23", "%s"); print $date;
            >> >> > -> -787021200
            >> >> >
            >> >> >So, how come MySQL can't do it, PHP can't do it, but somehow perl can?
            >> >> >Can I compile PHP with negative integer date support?
            >> >>
            >> >> I think it depends on the underlying unix libraries. I think a better
            >> >> approach would IMO to write a library based on the MySQL date functions
            >> >> (or any other database), which should support date support from 1908-xxxx
            >> >> or earlier.
            >> >
            >> >Eh, I don't understand... Are you recommending I use MySQL to obtain dates
            >> >earlier than 1970 even though I showed above that MySQL doesn't support it
            >> >either...? I am confused.
            >> >
            >> >To recap again. MySQL doesn't support it, PHP doesn't support it, Perl
            >> >supports it.[/color]
            >>
            >> If you look at http://www.mysql.com/doc/en/Date_and...functions.html
            >>
            >> and just do not use any %UNIX% functions, you should be fine. I just tested
            >>
            >> SELECT INTERVAL 1 DAY + '1925-12-31'
            >>
            >> and its New Years day 1926.[/color]
            >
            >I realize that - but perhaps I was unclear at what I wanted. I WANT the unix
            >timestamp of a given date.
            >
            >select unix_timestamp( "1985-01-01");
            > -> 473382000
            >
            >select unix_timestamp( "1925-01-01");
            > -> 0[/color]

            Thats because the Unix Epoch is from 1970 to 2038. The result is IMO
            undefined for dates outside.
            [color=blue]
            >
            >What that other select SHOULD return is "-1420074000" and THAT's what I want. I
            >want a function, prefferably in PHP, that will return "-1420074000" when I feed
            >it with "1925-01-01".[/color]

            Its an understandable opinion, but I would dicuss it with the guys
            that do the unix date libraries. That might clear it.

            HTH, Jochen

            --
            Jochen Daum - Cabletalk Group Ltd.
            PHP DB Edit Toolkit -- PHP scripts for building
            database editing interfaces.
            Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

            Comment

            • Sandman

              #7
              Re: mktime() and UNIXTIME epoch.

              In article <f7g730t2169nau 8l0b9g07capd8ij 9grmt@4ax.com>,
              Jochen Daum <jochen.daum@ca ns.co.nz> wrote:
              [color=blue][color=green]
              > >I realize that - but perhaps I was unclear at what I wanted. I WANT the unix
              > >timestamp of a given date.
              > >
              > >select unix_timestamp( "1985-01-01");
              > > -> 473382000
              > >
              > >select unix_timestamp( "1925-01-01");
              > > -> 0[/color]
              >
              > Thats because the Unix Epoch is from 1970 to 2038. The result is IMO
              > undefined for dates outside.[/color]

              Well, the unix epoch is system-dependant, on some unix systems it's frm 1970,
              and from some it's 1904. It all depends on whether the date integer can handle
              inverse values (i.e. 0 is 1970-01-01 00:00:00 and -1 is 1969-12-31 23:59:59).
              It's the scope of a 32 bit integer.
              [color=blue][color=green]
              >> What that other select SHOULD return is "-1420074000" and THAT's what
              >> I want. I want a function, prefferably in PHP, that will return
              >> "-1420074000" when I feed it with "1925-01-01".[/color]
              >
              > Its an understandable opinion, but I would dicuss it with the guys
              > that do the unix date libraries. That might clear it.[/color]

              Yes, it seems they don't use the system date functions, and I was hoping to
              find a way to make PHP do the same... :/

              --
              Sandman[.net]

              Comment

              • boclair

                #8
                Re: mktime() and UNIXTIME epoch.


                "Sandman" <mr@sandman.net > wrote in message
                news:mr-3FF6A7.09463419 022004@news.fu-berlin.de...[color=blue]
                > In article <f7g730t2169nau 8l0b9g07capd8ij 9grmt@4ax.com>,
                > Jochen Daum <jochen.daum@ca ns.co.nz> wrote:[/color]
                [color=blue][color=green][color=darkred]
                > >> What that other select SHOULD return is "-1420074000" and THAT's what
                > >> I want. I want a function, prefferably in PHP, that will return
                > >> "-1420074000" when I feed it with "1925-01-01".[/color][/color][/color]
                [color=blue]
                > it seems they don't use the system date functions, and I was hoping to
                > find a way to make PHP do the same... :/[/color]

                How about returning -1420052400 instead?

                Have you looked at ADOdb?

                I've a scratch page with various conversions at
                http://www.boclair.com/adodb_test-time2.php.

                Louise


                Comment

                • Sandman

                  #9
                  Re: mktime() and UNIXTIME epoch.

                  In article <c16avg$1ehcrr$ 1@ID-210679.news.uni-berlin.de>,
                  "boclair" <boclair@bigpon d.net.au> wrote:
                  [color=blue][color=green][color=darkred]
                  > > >> What that other select SHOULD return is "-1420074000" and THAT's what
                  > > >> I want. I want a function, prefferably in PHP, that will return
                  > > >> "-1420074000" when I feed it with "1925-01-01".[/color][/color]
                  >[color=green]
                  > > it seems they don't use the system date functions, and I was hoping to
                  > > find a way to make PHP do the same... :/[/color]
                  >
                  > How about returning -1420052400 instead?
                  >
                  > Have you looked at ADOdb?
                  >
                  > I've a scratch page with various conversions at
                  > http://www.boclair.com/adodb_test-time2.php.[/color]

                  Hello - that looks nice!

                  What is ADOdb? How do I get the adodb.inc.php file?

                  --
                  Sandman[.net]

                  Comment

                  • boclair

                    #10
                    Re: mktime() and UNIXTIME epoch.


                    "Sandman" <mr@sandman.net > wrote in message
                    news:mr-07F535.15573421 022004@news.fu-berlin.de...[color=blue]
                    > In article <c16avg$1ehcrr$ 1@ID-210679.news.uni-berlin.de>,
                    > "boclair" <boclair@bigpon d.net.au> wrote:
                    >
                    >
                    > What is ADOdb? How do I get the adodb.inc.php file?
                    >[/color]

                    A GPL program consisting of libraries and PHP classes which standardizes
                    access across many (most) database programs. Does much more than just
                    date/time conversions. Very powerful.

                    See http://php.weblogs.com/adodb .

                    To begin you might find the following useful.


                    Louise



                    Comment

                    • Sandman

                      #11
                      Re: mktime() and UNIXTIME epoch.

                      In article <c18suj$1ffhig$ 1@ID-210679.news.uni-berlin.de>,
                      "boclair" <boclair@bigpon d.net.au> wrote:
                      [color=blue][color=green]
                      > > What is ADOdb? How do I get the adodb.inc.php file?[/color]
                      >
                      > A GPL program consisting of libraries and PHP classes which standardizes
                      > access across many (most) database programs. Does much more than just
                      > date/time conversions. Very powerful.
                      >
                      > See http://php.weblogs.com/adodb .
                      >
                      > To begin you might find the following useful.
                      > http://www.phpfreaks.com/tutorials/110/0.php[/color]

                      Ok, now I'm confused. This seems to be a Database bridge API, to make the
                      database backend to a PHP frontend interchangeable .

                      Well, first off - that seems a bit tad over the top to implement just to do
                      what I wanted.

                      And second - how do I know that the function adodb_mktime() doesn't use a
                      database backend to perform this query and it is the functions of THAT database
                      that enables mktime() to reference dates older than 1970?

                      Now, presumably I could just download it and look at the source - but posting
                      this was more fun. :)

                      --
                      Sandman[.net]

                      Comment

                      • boclair

                        #12
                        Re: mktime() and UNIXTIME epoch.

                        The central purpose of ADOdb is, as you say, to allow standardized
                        connections to various db engines and to query, insert etc data table
                        through php scripting.

                        However once results have been got there are a number of functions available
                        for manipulating the
                        result variables, including date/time. However the variables can be
                        created in any manner including directly as in the scratch page at
                        Extensive selection of high-quality domain names. Knowledgeable, friendly customer support.


                        The library is very light but if you want to slim it down further,
                        adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
                        access it).

                        The functions are at http://php.weblogs.com/adodb_date_time_library.

                        Louise
                        The central purpose of ADOdb is, as you say, to allow standardized
                        connections to various db engines and to query, insert etc data table
                        through php scripting.

                        However once results have been got there are a number of functions available
                        for manipulating the
                        result variables, including date/time. However the variables can be
                        created in any manner including directly as in the scratch page at
                        Extensive selection of high-quality domain names. Knowledgeable, friendly customer support.


                        The library is very light but if you want to slim it down further,
                        adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
                        access it).

                        The functions are at http://php.weblogs.com/adodb_date_time_library.

                        Louise

                        "Sandman" <mr@sandman.net > wrote in message
                        news:mr-25A8CF.21092122 022004@news.fu-berlin.de...[color=blue]
                        > In article <c18suj$1ffhig$ 1@ID-210679.news.uni-berlin.de>,
                        > "boclair" <boclair@bigpon d.net.au> wrote:
                        >[color=green][color=darkred]
                        > > > What is ADOdb? How do I get the adodb.inc.php file?[/color]
                        > >
                        > > A GPL program consisting of libraries and PHP classes which[/color][/color]
                        standardizes[color=blue][color=green]
                        > > access across many (most) database programs. Does much more than just
                        > > date/time conversions. Very powerful.
                        > >
                        > > See http://php.weblogs.com/adodb .
                        > >
                        > > To begin you might find the following useful.
                        > > http://www.phpfreaks.com/tutorials/110/0.php[/color]
                        >
                        > Ok, now I'm confused. This seems to be a Database bridge API, to make the
                        > database backend to a PHP frontend interchangeable .
                        >
                        > Well, first off - that seems a bit tad over the top to implement just to[/color]
                        do[color=blue]
                        > what I wanted.
                        >
                        > And second - how do I know that the function adodb_mktime() doesn't use a
                        > database backend to perform this query and it is the functions of THAT[/color]
                        database[color=blue]
                        > that enables mktime() to reference dates older than 1970?
                        >
                        > Now, presumably I could just download it and look at the source - but[/color]
                        posting[color=blue]
                        > this was more fun. :)
                        >
                        > --
                        > Sandman[.net][/color]


                        Comment

                        • Sandman

                          #13
                          Re: mktime() and UNIXTIME epoch.

                          In article <c1bfig$1h2388$ 1@ID-210679.news.uni-berlin.de>,
                          "boclair" <boclair@bigpon d.net.au> wrote:
                          [color=blue]
                          > The central purpose of ADOdb is, as you say, to allow standardized
                          > connections to various db engines and to query, insert etc data table
                          > through php scripting.
                          >
                          > However once results have been got there are a number of functions available
                          > for manipulating the
                          > result variables, including date/time. However the variables can be
                          > created in any manner including directly as in the scratch page at
                          > http://www.boclair.com/adodb_test-time2.php
                          >
                          > The library is very light but if you want to slim it down further,
                          > adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
                          > access it).
                          >
                          > The functions are at http://php.weblogs.com/adodb_date_time_library.[/color]

                          Regardless of databases, the TIME functions was seperately downloadable, and
                          they work just fine!

                          Thanks!

                          --
                          Sandman[.net]

                          Comment

                          Working...