A proper date conversion function?
fernando.olmos at hpa.com.au
fernando.olmos at hpa.com.au
Thu Sep 20 19:53:08 CDT 2007
Hi everyone.
This is interesting... there must be a good date conversion function,
using defines, out there that is better than mine...
This only works with dd/mm/yyyy, where dd and mm can be either single or
two values. What if the field t_field_03 (char*50 by the way) has an
invalid date like "1212/344/54874" or a valid date of ddmmyyyy?
>From the client that sends us the files, they can send us anything,
including any valid date like ddmmyyyy, dd-mm-yyyy, dmy, dmmyyyy,
ddmyyyy, dmyyyy, etc... so we have to cater for all possible dates. It's
a shame COGNOS didn't think of writing a dateconv() function that
actually converts any date to a valid date data type. If there is one,
please let me know as I am pulling out my hair with all these defines!
hehehe
;Get the date required, but making sure that day and month
;is properly adjusted if they are single digits. Format of the
;date has to come in with 'slash' characters in the format: dd/mm/yyyy
define t_slash1 num*2 = index(t_field_03,"/")
define t_mmyyyy char*7 = t_field_03[(t_slash1 + 1):7]
define t_slash2 num*2 = index(t_mmyyyy,"/")
define t_date_required_d char*2 = t_field_03[1:(t_slash1 - 1)] &
if t_slash1 > 2 and t_rec_type = 1 &
else "0" + t_field_03[1:(t_slash1 - 1)] &
if t_rec_type = 1
define t_date_required_m char*2 = t_mmyyyy[1:(t_slash2 - 1)] &
if t_slash2 > 2 and t_rec_type = 1 &
else "0" + t_mmyyyy[1:(t_slash2 - 1)] &
if t_rec_type = 1
define t_date_required_y char*4 = t_mmyyyy[(index(t_mmyyyy,"/") + 1):4]
&
if t_rec_type = 1
define t_date_required_c char*8 = pack(trunc(t_date_required_y) + &
trunc(t_date_required_m) + &
trunc(t_date_required_d)) &
if t_num_error <> "C" &
and t_rec_type = 1 &
else "0"
define t_date_required date = nconvert(t_date_required_c)
**********************************************************************
IMPORTANT
The contents of this e-mail and its attachments are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you received this e-mail in error, please notify the HPA Postmaster, postmaster at hpa.com.au,
then delete the e-mail.
This footnote also confirms that this e-mail message has been swept for the
presence of computer viruses by Ironport. Before opening or using any
attachments, check them for viruses and defects.
Our liability is limited to resupplying any affected attachments.
HPA collects personal information to provide and market our services. For more
information about use, disclosure and access see our Privacy Policy at
www.hpa.com.au
**********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sowder.com/pipermail/powerh-l/attachments/20070921/17cbbeb9/attachment.html
More information about the powerh-l
mailing list