Question
Yone Moreno · Jan 27, 2021

Convert HL7 date with and without hours part

Hello,

We would need some help, please;

We would like to handle when we have a date with hours:

20201204090000

And when we have it without the hours part, as follows:

20201204

 

For the first case we used:

##class(Ens.Util.Time).ConvertDateTime(source.{ORCgrp(1).RXA:DateTimeStartofAdministratio},"%Y%m%d%H%M%S","%d/%m/%Y",,.tSC)

For the second one we wrote:

##class(Ens.Util.Time).ConvertDateTime(source.{ORCgrp(1).RXA:DateTimeStartofAdministratio},"%Y%m%d","%d/%m/%Y",,.tSC)

 

However each way only works for one case

 

How could we handle both cases with just a line of code?

 

We have read:

https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic....

 

Thanks for your help

 

00
1 0 1 38

Replies

##class(Ens.Util.Time).ConvertDateTime($e(source.{ORCgrp(1).RXA:DateTimeStartofAdministratio}_"000000",1,14),"%Y%m%d%H%M%S","%d/%m/%Y",,.tSC)

should save your problem. then default time is 00:00:00

Or without any time

##class(Ens.Util.Time).ConvertDateTime($e(source.{ORCgrp(1).RXA:DateTimeStartofAdministratio},1,8),"%Y%m%d","%d/%m/%Y",,.tSC)