changing format of $date

Author: lalitpct@gmail.com (lalitpct)


when I evalute $date it gives current date , how it can be formatted for a specific type like "DD-MM-YYYY".
Without changing the set up of the application

13 Comments

  1. if all other things fail:

    write a function returning a formatted string (parameters are the date and the format you like)

    Think Ingo Stiller has some code already for his format/deformat handling of dates etc,

    HIH, Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. Good candidate for a wish, to have a builtin function returning a string following a certain format, for a certain type. In this case, we have a date and want a string with a specific date format (maybe using the current locale format?...).

    With a little bit a reflexion, I'm sure we could define a good wish for a super, yet simple to use, builtin function, or this kind of process.

    Kind regards,
    Richard


    Author: richard.gill (richard.gill@agfa.com)
  3. Hi Richard,

    as I see the faite of the wishes decomposing on uniface.info (never been contacted on one of my ones),
    I strongly recommend not to ask CPWR to do what we can do on our own as well.

    I gave up the dITo initiative after some 2 years, so someone else should come up with an  "open source".

    Uli

    P.S. I wonder where CPWR talks to his customers, for sure not here on uniface.info

    Seeing that the last report ("Hitlist") on wishes is much more than a year old;
    I name this some kind of pacifier for us, the paying customers
    rather than a gateway for CPWR to learn what is required "in the field".

    I think most of us provide a much better usability to their customers
    than we encounter day by day with the IDFand the uniface language.


    Author: ulrich-merkel (ulrichmerkel@web.de)
  4. Something similar to this might do the trick.

    ; Central Proc

    ;-----------------------------------------------------------------------

    ; CP_DISP_DATETIME

    ; Format the date to a viewable format for export

    ;-----------------------------------------------------------------------

    params

     

    datetime PV_DATETIME:INstring PV_DISPLAY_DATETIME:OUT

    endparams

    PV_DISPLAY_DATETIME =

    "%%PV_DATETIME[M]%%%/%%PV_DATETIME[D]%%%/%%PV_DATETIME[Y]%%% %%PV_DATETIME[9:2]%%%:%%PV_DATETIME[11:2]%%%"

    return

    (0)

     

     


    Author: dmanchester (dave.manchester@nucor.com)
  5. Hi Dave,

    thanks for your input (breaking the ice) which is a very good starter for further discussions.

    To come near to the start of this thread, we can add another parameter and a selectcase for different options of the layout:

    string p_formatoption : IN
    selectcase (p_formatoption)
       case 'yy-mm-dd'
          PV_DISPLAY_DATETIME = "%%PV_DATETIME[Y]%%%-%%PV_DATETIME[M]%%%-%%PV_DATETIME[D]%%%"
      elsecase  
          PV_DISPLAY_DATETIME = "%%PV_DATETIME[M]%%%/%%PV_DATETIME[D]%%%/%%PV_DATETIME[Y]%%% %%PV_DATETIME[9:2]%%%:%%PV_DATETIME[11:2]%%%"
    endselectcase

    Uli

    P.S. It's good to see someone contributing rather than just consuming.


    Author: ulrich-merkel (ulrichmerkel@web.de)
  6. returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT

    v_outstring = p_formatoption

    v_outstring = replace(v_outstring,1,"yyyy","%%pv_datetime[Y]%%%",-1)
    v_outstring = replace(v_outstring,1,"yy","%%pv_datetime[Y]%%%[3:2]",-1)
    v_outstring = replace(v_outstring,1,"mm","%%pv_datetime[M]%%%",-1)
    v_outstring = replace(v_outstring,1,"dd","%%pv_datetime[D]%%%",-1)
    etc.
    etc.

    return v_outstring
    end

    or alternatively,

    returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT
    variables
    string v_pairs
    endvariables

    putitem/id v_pairs,"YYYY","%%pv_datetime[Y]%%%"
    putitem/id v_pairs,"YY","%%pv_datetime[Y]%%%[2:3]"
    putitem/id v_pairs,"mm","%%pv_datetime[M]%%%"
    ....... etc

    v_outstring = p_formatoption

    while(v_pairs != "")
    v_outstring = replace(v_outstring,1,$idpart($itemnr(1,v_pairs)),$valuepart($itemnr(1,v_pairs)),-1)
    delitem v_pairs,1
    endwhile

    return v_outstring
    end


    Both of these allow the user to pass the format to be used.


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  7. returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT

    v_outstring = p_formatoption

    v_outstring = replace(v_outstring,1,"yyyy","%%pv_datetime[Y]%%%",-1)
    v_outstring = replace(v_outstring,1,"yy","%%pv_datetime[Y]%%%[3:2]",-1)
    v_outstring = replace(v_outstring,1,"mm","%%pv_datetime[M]%%%",-1)
    v_outstring = replace(v_outstring,1,"dd","%%pv_datetime[D]%%%",-1)
    etc.
    etc.

    return v_outstring
    end

    or alternatively,

    returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT
    variables
    string v_pairs
    endvariables

    putitem/id v_pairs,"YYYY","%%pv_datetime[Y]%%%"
    putitem/id v_pairs,"YY","%%pv_datetime[Y]%%%[2:3]"
    putitem/id v_pairs,"mm","%%pv_datetime[M]%%%"
    ....... etc

    v_outstring = p_formatoption

    while(v_pairs != "")
    v_outstring = replace(v_outstring,1,$idpart($itemnr(1,v_pairs)),$valuepart($itemnr(1,v_pairs)),-1)
    delitem v_pairs,1
    endwhile

    return v_outstring
    end


    Both of these allow the user to pass the format to be used.


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  8. returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT

    v_outstring = p_formatoption

    v_outstring = replace(v_outstring,1,"yyyy","%%pv_datetime[Y]%%%",-1)
    v_outstring = replace(v_outstring,1,"yy","%%pv_datetime[Y]%%%[3:2]",-1)
    v_outstring = replace(v_outstring,1,"mm","%%pv_datetime[M]%%%",-1)
    v_outstring = replace(v_outstring,1,"dd","%%pv_datetime[D]%%%",-1)
    etc.
    etc.

    return v_outstring
    end

    or alternatively,

    returns string
    datetime pv_datetime : in
    string p_formatoption : IN
    string v_outstring : OUT
    variables
    string v_pairs
    endvariables

    putitem/id v_pairs,"YYYY","%%pv_datetime[Y]%%%"
    putitem/id v_pairs,"YY","%%pv_datetime[Y]%%%[2:3]"
    putitem/id v_pairs,"mm","%%pv_datetime[M]%%%"
    ....... etc

    v_outstring = p_formatoption

    while(v_pairs != "")
    v_outstring = replace(v_outstring,1,$idpart($itemnr(1,v_pairs)),$valuepart($itemnr(1,v_pairs)),-1)
    delitem v_pairs,1
    endwhile

    return v_outstring
    end


    Both of these allow the user to pass the format to be used.


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  9. Hi,

     

    if the demanded format is fix, why don't use a component variable?

    So the code will become very smal, but you have to maintain this variables

    ; -- define $dMyDate$ with Layout DIS(yyyy-mm-dd)

    $dMyDate$ = $date()

    myText = "%%$dMyDate$%%%" ; important here you need substitution!

    message myText

     

    Of course depending how offen you need this and how flexible you must be for maintenance (but change component-var can be done, by updaten Repos ;))

    Best regards

    Thomas


    Author: Thomas.Young (thomas.young@young-consulting.de)
  10. Hi Iain,

    a great example with a lot of flexibility in it.

    At least 10 stars of excellence for this contribution.

    Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)
  11. Hi all,

    Here I give you an alternative way to change the date format in 1 statement:

    $1 = $concat ("0%%$date[d]%%%"[($length($date[d])),($length($date[d]))+1], "-",  "0%%$date[M]%%%"[($length($date[M])),($length($date[M]))+1] , "-",  "%%$date[Y]%%%")

    regards Jip Westerman

     


    Author: Jip Westerman (jipwesterman@gmail.com)
  12. Hi Jip,

    .. a very clever way for padding leading characters in just 1 line of code.

    A lot of "stars of excellence" from me

    Uli

    www.uli-merkel.de * ulrichmerkel@web.de


    Author: ulrich-merkel (ulrichmerkel@web.de)
  13. Hi

    I didn't know the string extraction could apply to string literals, good to know, far more than the date format :)


    Author: richard.gill (richard.gill@agfa.com)