Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Date Values Into Character Field 1

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
I have a date field defined in my D spec set to the run date
by setting the dte thus:-

TodaysDate = %Date();

I then extract each date element into a character string
using this command:-


H2LDATE = %Char(%Subdt(TodaysDate:*YEARS))
+ %Char(%Subdt(TodaysDate:*MONTHS))
+ %Char(%Subdt(TodaysDate:*DAYS));

The problem is that instead of '20040517', I get
'2004517 '.
Leading zeroes are dropped instead of represented by '0'.
Whats the best way to get round this?



Dazed and confused
 
Define Num as 8S 0

C *ISO Move Todaysdate Num
C Eval H2LDate = %char(Num)

or even easier

C *ISO Move *Date Num
C Eval H2LDate = %char(Num)
 
Good grief, of course!

Many thanks.

Dazed and confused
 
Even easier:

Code:
H2LDate = %char(%date(num:*ISO));

Here is how I convert a numeric CYYMMDD date to USA format 10-character field (mm/dd/yyyy):

Code:
Test(De) *CYMD Rrdued;	//Due Date
If Not %ERROR;
Cdfedd = %CHAR(%DATE(Rrdued:*CYMD):*USA/);	// Cyymmdd To 'mm/dd/ccyy'
Else;
Cdfedd = *BLANKS;	// Default Date
Endif;	// Not %ERROR


De mortuis nihil nisi bonum.

 
Oops. On that first code sample, since all you want is today's date, it should have been:

Code:
H2LDate = %char(%date);

%DATE by itself will return the current system date.

De mortuis nihil nisi bonum.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top