Loading ...
Sorry, an error occurred while loading the content.

AW: [libertybasic] Re: Dates and times

Expand Messages
  • Stefan Pendl
    ... Actually the algoritm Stefan provided is not 100% correct: it is possible to get non-true time names, like a filename ending on 180260 (after 18:02:59) The
    Message 1 of 2 , Nov 29, 2006
    • 0 Attachment
      >>Dear Peter, Stefan,


      Actually the algoritm Stefan provided is not 100% correct: it is
      possible to get non-true time names, like a filename ending on
      180260 (after 18:02:59)
      The same problems occurs when you pass 23:59:59
      and what comes after april 30?
      At last we have the problem of a leap-year ....

      Can be solved, but you need some more lines of code.

      Stefan Hesseling
      <<

      Hello Stefan,
      Peter just asked for a file name that would include the current date and time plus one second.
      If the file name should be correct in terms of dates and times, then the addition of one second should be omitted.

      ---
      Stefan Pendl








      ___________________________________________________________
      Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

      [Non-text portions of this message have been removed]
    • asdeskmichael
      ... current date and time plus one second. ... the addition of one second should be omitted. ... I do not know if this will help you or not; but I have created
      Message 2 of 2 , Dec 1, 2006
      • 0 Attachment
        --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@...>
        wrote:
        >
        > >>Dear Peter, Stefan,
        >
        >
        > Actually the algoritm Stefan provided is not 100% correct: it is
        > possible to get non-true time names, like a filename ending on
        > 180260 (after 18:02:59)
        > The same problems occurs when you pass 23:59:59
        > and what comes after april 30?
        > At last we have the problem of a leap-year ....
        >
        > Can be solved, but you need some more lines of code.
        >
        > Stefan Hesseling
        > <<
        >
        > Hello Stefan,
        > Peter just asked for a file name that would include the
        current date and time plus one second.
        > If the file name should be correct in terms of dates and times, then
        the addition of one second should be omitted.
        >
        > ---
        > Stefan Pendl
        >
        >

        I do not know if this will help you or not; but I have created this
        code to format dates and so on. It is preety self explanatory...

        'ASdesk Time Machine
        'by: Michael A. Smith
        '
        'Read the Following for format info...
        '
        'Date Functions
        '
        ' M = Month Abbrev (ex: Jan)
        ' z = Full Month Name (ex: January)
        ' m = Month Number (leading zero)
        ' d = Day (leading zero)
        ' Y = Full Year (ex: 2006)
        ' y = Short Year (ex: 06)
        ' any other values are printed in result ex: if
        ' FormatTo$= "M d, Y" would print (if today is January 1st in year 2007)
        ' Print FormatTo$ '= Jan 1, 2007
        '
        'Examples
        ' M d, y = Jan 01, 2007
        ' m/d/y = 01/01/07
        ' M d Y = Jan 01 2007
        '
        'Time Functions
        ' A = AM/PM (depending on time)
        ' a = am/pm (depending on time)
        ' H = Hour (military time)
        ' h = Hour (am / pm)
        ' C = Minute
        ' S = Second(s)
        '

        ' Final Example (prints the full date and full time in am/pm)
        ' z d, Y @ h:C a = January 01, 2006 @ 12:00 pm
        [setup.app]

        FormatTo$ = "z d, Y @ h:C a" 'The data you are going to format with.

        AllowExtraDataToPrint$ = "yes" 'if set to no;
        ' only above code functions will work
        ' (no formatting with extra characters, keep as yes)

        'DO NOT EDIT >
        FormatToLEN = len(FormatTo$)
        TimeNow$ = time$()
        DateNow$ = date$()

        [date.functions]
        MonthAbbrv$ = mid$(DateNow$, 1, 3)

        if MonthAbbrv$ = "Jan" then MonthN$="01"
        if MonthAbbrv$ = "Feb" then MonthN$="02"
        if MonthAbbrv$ = "Mar" then MonthN$="03"
        if MonthAbbrv$ = "Apr" then MonthN$="04"
        if MonthAbbrv$ = "May" then MonthN$="05"
        if MonthAbbrv$ = "Jun" then MonthN$="06"
        if MonthAbbrv$ = "Jul" then MonthN$="07"
        if MonthAbbrv$ = "Aug" then MonthN$="08"
        if MonthAbbrv$ = "Sep" then MonthN$="09"
        if MonthAbbrv$ = "Oct" then MonthN$ ="10"
        if MonthAbbrv$ = "Nov" then MonthN$ ="11"
        if MonthAbbrv$ = "Dec" then MonthN$ = "12"

        if MonthAbbrv$ = "Jan" then ActMonth$="January"
        if MonthAbbrv$ = "Feb" then ActMonth$="February"
        if MonthAbbrv$ = "Mar" then ActMonth$="March"
        if MonthAbbrv$ = "Apr" then ActMonth$="April"
        if MonthAbbrv$ = "May" then ActMonth$="May"
        if MonthAbbrv$ = "Jun" then ActMonth$="June"
        if MonthAbbrv$ = "Jul" then ActMonth$="July"
        if MonthAbbrv$ = "Aug" then ActMonth$="August"
        if MonthAbbrv$ = "Sep" then ActMonth$="September"
        if MonthAbbrv$ = "Oct" then ActMonth$="October"
        if MonthAbbrv$ = "Nov" then ActMonth$="November"
        if MonthAbbrv$ = "Dec" then ActMonth$="December"

        FullDay$ = mid$(DateNow$, 5, 2)

        FullYear$ = mid$(DateNow$, 9, 4) '2006
        ShortYear$ = mid$(FullYear$, 3,2) '06

        [time.functions]
        [interpet.hour]
        CurrHour$ = mid$(TimeNow$,1, 2)
        if CurrHour$ = "00" then ApmHr$ = "12"
        if CurrHour$ = "01" then ApmHr$ = "1"
        if CurrHour$ = "02" then ApmHr$ = "2"
        if CurrHour$ = "03" then ApmHr$ = "3"
        if CurrHour$ = "04" then ApmHr$ = "4"
        if CurrHour$ = "05" then ApmHr$ = "5"
        if CurrHour$ = "06" then ApmHr$ = "6"
        if CurrHour$ = "07" then ApmHr$ = "7"
        if CurrHour$ = "08" then ApmHr$ = "8"
        if CurrHour$ = "09" then ApmHr$ = "9"
        if CurrHour$ = "10" then ApmHr$ = "10"
        if CurrHour$ = "11" then ApmHr$ = "11"
        if CurrHour$ = "12" then ApmHr$ = "12"
        if CurrHour$ = "13" then ApmHr$ = "1"
        if CurrHour$ = "14" then ApmHr$ = "2"
        if CurrHour$ = "15" then ApmHr$ = "3"
        if CurrHour$ = "16" then ApmHr$ = "4"
        if CurrHour$ = "17" then ApmHr$ = "5"
        if CurrHour$ = "18" then ApmHr$ = "6"
        if CurrHour$ = "19" then ApmHr$ = "7"
        if CurrHour$ = "20" then ApmHr$ = "8"
        if CurrHour$ = "21" then ApmHr$ = "9"
        if CurrHour$ = "22" then ApmHr$ = "10"
        if CurrHour$ = "23" then ApmHr$ = "11"
        if CurrHour$ = "24" then ApmHr$ = "12"

        [interpet.am.pm]
        if CurrHour$ = "00" then standard$ = "am"
        if CurrHour$ = "01" then standard$ = "am"
        if CurrHour$ = "02" then standard$ = "am"
        if CurrHour$ = "03" then standard$ = "am"
        if CurrHour$ = "04" then standard$ = "am"
        if CurrHour$ = "05" then standard$ = "am"
        if CurrHour$ = "06" then standard$ = "am"
        if CurrHour$ = "07" then standard$ = "am"
        if CurrHour$ = "08" then standard$ = "am"
        if CurrHour$ = "09" then standard$ = "am"
        if CurrHour$ = "10" then standard$ = "am"
        if CurrHour$ = "11" then standard$ = "am"
        if CurrHour$ = "12" then standard$ = "pm"
        if CurrHour$ = "13" then standard$ = "pm"
        if CurrHour$ = "14" then standard$ = "pm"
        if CurrHour$ = "15" then standard$ = "pm"
        if CurrHour$ = "16" then standard$ = "pm"
        if CurrHour$ = "17" then standard$ = "pm"
        if CurrHour$ = "18" then standard$ = "pm"
        if CurrHour$ = "19" then standard$ = "pm"
        if CurrHour$ = "20" then standard$ = "pm"
        if CurrHour$ = "21" then standard$ = "pm"
        if CurrHour$ = "22" then standard$ = "pm"
        if CurrHour$ = "23" then standard$ = "pm"
        if CurrHour$ = "24" then standard$ = "pm"

        CurrMin$ = mid$(TimeNow$, 4, 2)
        CurrSec$ = mid$(TimeNow$, 7, 2)

        [run.interpeter]

        'Add The interpeter (translates data for print)
        'a$ = ""
        DataToPrint$ = ""

        for a = 1 to FormatToLEN
        a$ = mid$(FormatTo$, a, 1)

        [functions]
        'Date Functions
        if a$ = "z" then DataToPrint$ = DataToPrint$;ActMonth$
        if a$ = "z" then [next.val]
        if a$ = "M" then DataToPrint$ = DataToPrint$;MonthAbbrv$
        if a$ = "M" then [next.val]

        if a$ = "m" then DataToPrint$ = DataToPrint$;MonthN$
        if a$ = "m" then [next.val]

        if a$ = "d" then DataToPrint$ = DataToPrint$;FullDay$
        if a$ = "d" then [next.val]

        if a$ = "Y" then DataToPrint$ = DataToPrint$;FullYear$
        if a$ = "Y" then [next.val]

        if a$ = "y" then DataToPrint$ = DataToPrint$;ShortYear$
        if a$ = "y" then [next.val]

        'Time Functions
        [standard.am.pm.func]
        if standard$ = "am" and a$="A" then toPrintA1$ = "AM"
        if standard$ = "am" and a$="a" then toPrintA2$ = "am"
        if standard$ = "pm" and a$="A" then toPrintA1$ = "PM"
        if standard$ = "pm" and a$="a" then toPrintA2$ = "pm"

        if a$ = "A" then DataToPrint$=DataToPrint$;toPrintA1$
        if a$ = "a" then DataToPrint$=DataToPrint$;toPrintA2$
        if a$ = "A" then [next.val]
        if a$ = "a" then [next.val]

        if a$ = "H" then DataToPrint$=DataToPrint$;CurrHour$
        if a$ = "H" then [next.val]

        if a$ = "h" then DataToPrint$=DataToPrint$;ApmHr$
        if a$ = "h" then [next.val]

        if a$ = "C" then DataToPrint$=DataToPrint$;CurrMin$
        if a$ = "C" then [next.val]

        if a$ = "S" then DataToPrint$=DataToPrint$;CurrSec$
        if a$ = "S" then [next.val]

        if AllowExtraDataToPrint$ = "no" then [next.val]
        DataToPrint$ = DataToPrint$;a$
        [next.val]
        next a

        '< DO NOT EDIT

        'The Results are Stored in DataToPrint$
        '
        print "Results..."
        print ""
        print DataToPrint$
      Your message has been successfully submitted and would be delivered to recipients shortly.