KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting UTC date/time into short date
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: February 3, 2006

Date and date/time values transmitted via the web (in XML format, for example) are usually formatted with ISO 8601 standard as specified on W3 site:

https://www.w3.org/TR/xmlschema-2/#isoformats
https://www.w3.org/TR/NOTE-datetime

The following method converts a date or date/time value from the YYYY-MM-DDThh:mm: format into a short string based on the system date settings. This is very useful in converting received XML date/time data into more human readable format.

  ` Parameters:

  ` $1 : Text : A date or date-time value

  ` Returns:

  ` $0 : Text : An end user date


C_TEXT($0;$1;$date_t;$time_t)

C_LONGINT($year_i;$month_i;$day_i)

C_DATE($date_d)

C_TIME($time_h)


$date_t:=$1


If (Length($date_t)=24)  ` It's a date and time value.

$time_t:=Substring($date_t;12;8)



$time_t:=String(Time($time_t);HH MM SS )

$time_h:=Time($time_t)



$date_t:=Substring($date_t;1;10)

Else

$time_t:=""

End if


If (Length($date_t)=10)

$year_i:=Num(Substring($date_t;1;4))

$month_i:=Num(Substring($date_t;6;2))

$day_i:=Num(Substring($date_t;9;2))



$date_d:=SF4D_Date_YearMonthDayToDate ($year_i;$month_i;$day_i)



If ($time_t#"")

If ($time_h<◊difftime)

$date_d:=Add to date($date_d;0;0;-◊offsetdate)

$time_h:=Time($time_t)+◊addtime

Else

$time_h:=Time($time_t)-◊difftime

End if

$time_t:=" "+String($time_h;HH MM AM PM )

$date_t:=String($date_d;MM DD YYYY Forced )

Else

$date_t:=String($date_d;MM DD YYYY Forced )

$date_t:=Replace string($date_t;"/0";"/")  ` Get rid of the leading zeros.

If ($date_t="0@")

$date_t:=Substring($date_t;2)

End if

End if

End if

$0:=$date_t+$time_t