Skip to main content
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

Uniface 9: changing format of $date

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 replies

Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:28 AM UTC

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

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)