Announcement

Collapse
No announcement yet.

Free Date and Time Function using PHP "date()" style formatting.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Free Date and Time Function using PHP "date()" style formatting.



    ------=_NextPart_000_001F_01C4FBEF.FDE56000
    Content-Type: text/plain;
    charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable

    Hi all!

    The "Date and Time Function" request a week or so ago inspired me to =
    update my function that I supplied. I wanted to see how closely I could =
    emulate the date() function in PHP, and this is the result.

    It's fully tested, 3.9x compliant (I don't own a compiler to test 4.x, =
    but I think it would compile?), and works perfectly on my machine.

    Current format codes supported:

    Format Description (Example)
    DAY =
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D
    d Day of the month, 2 digits with leading zeros (01 - 31)
    D A textual representation of a day, three letters (Sun - Sat)
    j Day of the month without leading zeros (1 - 31)
    l Lower-case 'L' - A full textual representation of the day of the =
    week (Sunday - Saturday)

    MONTH =
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D
    F A full textual representation of a month (January - December)
    m Numeric representation of a month, with leading zeros (01 - 12)
    M A short textual representation of a month, three letters (Jan - =
    Dec)
    n Numeric representation of a month, without leading zeros (1 - 12)

    YEAR =
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D
    Y A full numeric representation of a year (2000 or 2001)
    y A two digit representation of a year (00 or 01)

    TIME =
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D
    a Lowercase Ante meridiem and Post meridiem (am or pm)
    A Uppercase Ante meridiem and Post meridiem (AM or PM)
    g 12-hour format of an hour without leading zeros (1 - 12)
    h 12-hour format of an hour with leading zeros (01 - 12)
    i Minutes with leading zeros (00 - 59)
    s Seconds, with leading zeros (00 - 59)

    Currently format codes are opposite of PHP - preceed all format codes =
    with a backslash and enter everything else as normal text

    e.g. "/F /j, /Y, /g:/i /a" will outputs "March 10, 2001, 5:16 pm"

    <MvCOMMENT>
    | time_t_date(time_t, timezone, format) Use PHP date() format codes =
    with a preceeding backslash (e.g. '/F /j, /Y, /g:/i /a' outputs 'March =
    10, 2001, 5:16 pm')
    </MvCOMMENT>
    <MvFUNCTION name=3D"time_t_date" PARAMETERS=3D"cut,tz,format" =
    STANDARDOUTPUTLEVEL=3D"compresswhitespace" =
    ERROROUTPUTLEVEL=3D"syntax,expression,runtime">
    <MvASSIGN name=3D"l.months" =
    value=3D"January|February|March|April|May|June|Jul y|August|September|Octo=
    ber|November|December">
    <MvASSIGN NAME=3D"l.dayofweek" =
    VALUE=3D"Sunday|Monday|Tuesday|Wednesday|Thursday| Friday|Saturday">
    <MvASSIGN name=3D"l.hour" value=3D"{time_t_hour(l.cut,l.tz)}">
    <MvASSIGN name=3D"l.ampm" value=3D"am">
    <MvIF EXPR=3D"{l.hour GT 11}">
    <MvASSIGN name=3D"l.ampm" value=3D"pm">
    </MvIF>
    <MvIF EXPR=3D"{l.hour GT 12}">
    <MvASSIGN name=3D"l.hour" value=3D"{l.hour - 12}">
    </MvIF>
    <MvIF EXPR=3D"{l.hour LT 1}">
    <MvASSIGN name=3D"l.hour" value=3D"12">
    </MvIF>
    <MvASSIGN NAME=3D"l.format" =
    VALUE=3D"{glosub(glosub(glosub(glosub(glosub(glosu b(glosub(glosub(glosub(=
    glosub(glosub(glosub(glosub(glosub(glosub(glosub(l .format,'/d',padl(time_=
    t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',=
    time_t_dayofweek(l.cut,l.tz)),0,3)),'/j',time_t_dayofmonth(l.cut, =
    l.tz)),'/l',gettoken(l.dayofweek,'|',time_t_dayofweek(l.cut ,l.tz))),'/F',=
    gettoken(l.months,'|',time_t_month(l.cut,l.tz))),'/m',padl(time_t_month(l=
    .cut,l.tz),2,'0')),'/M',substring(gettoken(l.months,'|',time_t_month(l. cu=
    t, =
    l.tz)),0,3)),'/n',time_t_month(l.cut,l.tz)),'/Y',time_t_year(time_t,time_=
    zone)),'/y',substring(time_t_year(time_t,time_zone),3,2)),'/a',l.ampm),'/=
    A',toupper(l.ampm)),'/g',l.hour),'/h',padl(l.hour,2,'0')),'/i',padl(time_=
    t_min(l.cut, l.tz),2,'0')),'/s',padl(time_t_min(l.cut, l.tz),2,'0'))}">
    <MvFUNCRETURN VALUE=3D"{l.format}">
    </MvFUNCTION>

    It turned out to be only 106 bytes larger than my previous function, but =
    the level of customization I think greatly out-weighs that.

    Also, I haven't timed this, so I don't know how it performs compared to =
    the old function. I'm sure it's a fraction slower though.

    Finally, if the email servers eat it and destroy the code, you can =
    download it in .txt format here: =
    <A HREF ="http://www.winterboard.com/date_function.txt">http://www.winterboard.com/date_function.txt</A>

    Sincerely,
    - Tim Barkus
    ------=_NextPart_000_001F_01C4FBEF.FDE56000--

    #2
    Free Date and Time Function using PHP "date()" style



    Good job Tim, and thanks for sharing it.

    Jonathan
    Driftwood Network Services



    At 05:22 PM 1/16/2005, Tim Barkus wrote:
    >Hi all!
    >
    >The "Date and Time Function" request a week or so ago inspired me to
    >update my function that I supplied. I wanted to see how closely I could
    >emulate the date() function in PHP, and this is the result.
    >
    >It's fully tested, 3.9x compliant (I don't own a compiler to test 4.x, but
    >I think it would compile?), and works perfectly on my machine.
    >
    >Current format codes supported:
    >
    >Format Description (Example)
    >DAY ================================================== =========
    >d Day of the month, 2 digits with leading zeros (01 - 31)
    >D A textual representation of a day, three letters (Sun - Sat)
    >j Day of the month without leading zeros (1 - 31)
    >l Lower-case 'L' - A full textual representation of the day of the week
    >(Sunday - Saturday)
    >
    >MONTH ================================================== =======
    >F A full textual representation of a month (January - December)
    >m Numeric representation of a month, with leading zeros (01 - 12)
    >M A short textual representation of a month, three letters (Jan - Dec)
    >n Numeric representation of a month, without leading zeros (1 - 12)
    >
    >YEAR ================================================== ========
    >Y A full numeric representation of a year (2000 or 2001)
    >y A two digit representation of a year (00 or 01)
    >
    >TIME ================================================== ========
    >a Lowercase Ante meridiem and Post meridiem (am or pm)
    >A Uppercase Ante meridiem and Post meridiem (AM or PM)
    >g 12-hour format of an hour without leading zeros (1 - 12)
    >h 12-hour format of an hour with leading zeros (01 - 12)
    >i Minutes with leading zeros (00 - 59)
    >s Seconds, with leading zeros (00 - 59)
    >
    >Currently format codes are opposite of PHP - preceed all format codes with
    >a backslash and enter everything else as normal text
    >
    >e.g. "/F /j, /Y, /g:/i /a" will outputs "March 10, 2001, 5:16 pm"
    >
    ><MvCOMMENT>
    >| time_t_date(time_t, timezone, format) Use PHP date() format codes with
    >a preceeding backslash (e.g. '/F /j, /Y, /g:/i /a' outputs 'March 10,
    >2001, 5:16 pm')
    ></MvCOMMENT>
    ><MvFUNCTION name="time_t_date" PARAMETERS="cut,tz,format"
    >STANDARDOUTPUTLEVEL="compresswhitespace"
    >ERROROUTPUTLEVEL="syntax,expression,runtime">
    > <MvASSIGN name="l.months"
    > value="January|February|March|April|May|June|July| August|September|October|November|December">
    > <MvASSIGN NAME="l.dayofweek"
    > VALUE="Sunday|Monday|Tuesday|Wednesday|Thursday|Fr iday|Saturday">
    > <MvASSIGN name="l.hour" value="{time_t_hour(l.cut,l.tz)}">
    > <MvASSIGN name="l.ampm" value="am">
    > <MvIF EXPR="{l.hour GT 11}">
    > <MvASSIGN name="l.ampm" value="pm">
    > </MvIF>
    > <MvIF EXPR="{l.hour GT 12}">
    > <MvASSIGN name="l.hour" value="{l.hour - 12}">
    > </MvIF>
    > <MvIF EXPR="{l.hour LT 1}">
    > <MvASSIGN name="l.hour" value="12">
    > </MvIF>
    > <MvASSIGN NAME="l.format"
    > VALUE="{glosub(glosub(glosub(glosub(glosub(glosub( glosub(glosub(glosub(glosub(glosub(glosub(glosub(g losub(glosub(glosub(l.format,'/d',padl(time_t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',time_t_dayof week(l.cut,l.tz)),0,3)),'/j',time_t_dayofmonth(l.cut,
    > l.tz)),'/l',gettoken(l.dayofweek,'|',time_t_dayofweek(l.cut ,l.tz))),'/F',gettoken(l.months,'|',time_t_month(l.cut,l.tz)) ),'/m',padl(time_t_month(l.cut,l.tz),2,'0')),'/M',substring(gettoken(l.months,'|',time_t_month(l. cut,
    > l.tz)),0,3)),'/n',time_t_month(l.cut,l.tz)),'/Y',time_t_year(time_t,time_zone)),'/y',substring(time_t_year(time_t,time_zone),3,2)),'/a',l.ampm),'/A',toupper(l.ampm)),'/g',l.hour),'/h',padl(l.hour,2,'0')),'/i',padl(time_t_min(l.cut,
    > l.tz),2,'0')),'/s',padl(time_t_min(l.cut, l.tz),2,'0'))}">
    > <MvFUNCRETURN VALUE="{l.format}">
    ></MvFUNCTION>
    >
    >It turned out to be only 106 bytes larger than my previous function, but
    >the level of customization I think greatly out-weighs that.
    >
    >Also, I haven't timed this, so I don't know how it performs compared to
    >the old function. I'm sure it's a fraction slower though.
    >
    >Finally, if the email servers eat it and destroy the code, you can
    >download it in .txt format here: <A HREF ="http://www.winterboard.com/date_function.txt">http://www.winterboard.com/date_function.txt</A>
    >
    >Sincerely,
    >- Tim Barkus



    Comment


      #3
      Free Date and Time Function using PHP "date()" style formatting.



      Dear Tim,

      I was bored and tired of working, so I tried to compile your
      function....it compiled with no errors.

      Compiled size by itself is 3,341 bytes. Not that it means anything.

      Thought you might want to know it compiled OK.

      OK....play time over.....back to work.

      Thank you,

      Nerd Boy
      1-573-292-1136
      <A HREF ="http://www.nerdboyinc.com">http://www.nerdboyinc.com</A>
      <A HREF ="http://www.nerdboyproductions.com">http://www.nerdboyproductions.com</A>
      <A HREF ="http://www.nbicentral.com">http://www.nbicentral.com</A>
      <A HREF ="http://www.asmallurl.com">http://www.asmallurl.com</A>
      <A HREF ="http://www.yourlottosite.com">http://www.yourlottosite.com</A>

      For Customer Service and Support:
      http://suppert.nerdboyinc.com

      Follow The Nerd Boy
      Owner/ Driver Legends Car #99
      <A HREF ="http://www.nbiracing.com">http://www.nbiracing.com</A>

      ----- Original Message -----
      From: "Tim Barkus" <[email protected]>
      To: "Miva Users List" <[email protected]>
      Sent: Sunday, January 16, 2005 4:22 PM
      Subject: [meu] Free Date and Time Function using PHP "date()" style
      formatting.


      Hi all!

      The "Date and Time Function" request a week or so ago inspired me to update
      my function that I supplied. I wanted to see how closely I could emulate the
      date() function in PHP, and this is the result.

      It's fully tested, 3.9x compliant (I don't own a compiler to test 4.x, but I
      think it would compile?), and works perfectly on my machine.

      Current format codes supported:

      Format Description (Example)
      DAY ================================================== =========
      d Day of the month, 2 digits with leading zeros (01 - 31)
      D A textual representation of a day, three letters (Sun - Sat)
      j Day of the month without leading zeros (1 - 31)
      l Lower-case 'L' - A full textual representation of the day of the week
      (Sunday - Saturday)

      MONTH ================================================== =======
      F A full textual representation of a month (January - December)
      m Numeric representation of a month, with leading zeros (01 - 12)
      M A short textual representation of a month, three letters (Jan - Dec)
      n Numeric representation of a month, without leading zeros (1 - 12)

      YEAR ================================================== ========
      Y A full numeric representation of a year (2000 or 2001)
      y A two digit representation of a year (00 or 01)

      TIME ================================================== ========
      a Lowercase Ante meridiem and Post meridiem (am or pm)
      A Uppercase Ante meridiem and Post meridiem (AM or PM)
      g 12-hour format of an hour without leading zeros (1 - 12)
      h 12-hour format of an hour with leading zeros (01 - 12)
      i Minutes with leading zeros (00 - 59)
      s Seconds, with leading zeros (00 - 59)

      Currently format codes are opposite of PHP - preceed all format codes with a
      backslash and enter everything else as normal text

      e.g. "/F /j, /Y, /g:/i /a" will outputs "March 10, 2001, 5:16 pm"

      <MvCOMMENT>
      | time_t_date(time_t, timezone, format) Use PHP date() format codes with a
      preceeding backslash (e.g. '/F /j, /Y, /g:/i /a' outputs 'March 10, 2001,
      5:16 pm')
      </MvCOMMENT>
      <MvFUNCTION name="time_t_date" PARAMETERS="cut,tz,format"
      STANDARDOUTPUTLEVEL="compresswhitespace"
      ERROROUTPUTLEVEL="syntax,expression,runtime">
      <MvASSIGN name="l.months"
      value="January|February|March|April|May|June|July| August|September|October|November|December">
      <MvASSIGN NAME="l.dayofweek"
      VALUE="Sunday|Monday|Tuesday|Wednesday|Thursday|Fr iday|Saturday">
      <MvASSIGN name="l.hour" value="{time_t_hour(l.cut,l.tz)}">
      <MvASSIGN name="l.ampm" value="am">
      <MvIF EXPR="{l.hour GT 11}">
      <MvASSIGN name="l.ampm" value="pm">
      </MvIF>
      <MvIF EXPR="{l.hour GT 12}">
      <MvASSIGN name="l.hour" value="{l.hour - 12}">
      </MvIF>
      <MvIF EXPR="{l.hour LT 1}">
      <MvASSIGN name="l.hour" value="12">
      </MvIF>
      <MvASSIGN NAME="l.format"
      VALUE="{glosub(glosub(glosub(glosub(glosub(glosub( glosub(glosub(glosub(glosub(glosub(glosub(glosub(g losub(glosub(glosub(l.format,'/d',padl(time_t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',time_t_dayof week(l.cut,l.tz)),0,3)),'/j',time_t_dayofmonth(l.cut,
      l.tz)),'/l',gettoken(l.dayofweek,'|',time_t_dayofweek(l.cut ,l.tz))),'/F',gettoken(l.months,'|',time_t_month(l.cut,l.tz)) ),'/m',padl(time_t_month(l.cut,l.tz),2,'0')),'/M',substring(gettoken(l.months,'|',time_t_month(l. cut,
      l.tz)),0,3)),'/n',time_t_month(l.cut,l.tz)),'/Y',time_t_year(time_t,time_zone)),'/y',substring(time_t_year(time_t,time_zone),3,2)),'/a',l.ampm),'/A',toupper(l.ampm)),'/g',l.hour),'/h',padl(l.hour,2,'0')),'/i',padl(time_t_min(l.cut,
      l.tz),2,'0')),'/s',padl(time_t_min(l.cut, l.tz),2,'0'))}">
      <MvFUNCRETURN VALUE="{l.format}">
      </MvFUNCTION>

      It turned out to be only 106 bytes larger than my previous function, but the
      level of customization I think greatly out-weighs that.

      Also, I haven't timed this, so I don't know how it performs compared to the
      old function. I'm sure it's a fraction slower though.

      Finally, if the email servers eat it and destroy the code, you can download
      it in .txt format here: <A HREF ="http://www.winterboard.com/date_function.txt">http://www.winterboard.com/date_function.txt</A>

      Sincerely,
      - Tim Barkus


      Comment

      Working...
      X