Skip to main content
Question

DateFormat showing as null in AttributeCreator step

  • November 27, 2019
  • 5 replies
  • 40 views

I am passing a date UserParameter into a workbench and am then trying to convert it from the standard FME format to dd/mm/yyyy

Parameter is formatted as yyyy-mm-dd and if I just use the Parameter the value unformatted

it outputs as yyyyddmm eg 1950-01-01 becomes 19500101

I want it to output in dd/mm/yyyy format but if use dateformat($(PositionEffective).%d/%m/%y) a null is returned.

Thanks in advance

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • November 27, 2019

Are you on a older version of FME?  Should be DateTimeFormat with capital Y if you want 1950

@DateTimeFormat($(date),%d/%m/%Y)

Forum|alt.badge.img
  • 104 replies
  • November 27, 2019

You might have to force it with a DateTimeConverter after the AttributeCreator.


sipsysigh
Contributor
Forum|alt.badge.img+12
  • Contributor
  • 37 replies
  • November 27, 2019

Hi @left65,

As @ebygomm mentions, it looks like you got the syntax slightly wrong.

Instead of:

dateformat($(PositionEffective).%d/%m/%y)

in your example, it should be:

@DateTimeFormat($(PositionEffective),%d/%m/%Y)

 

You can use this function directly within the AttributeCreator, like this:

0684Q00000ArLIsQAN.png

Edited to actually include the screenshot! Not sure what happened there...

 

 

Hope this helps.

Si


Forum|alt.badge.img
  • 275 replies
  • November 27, 2019

Hi @left65

if the date comes in yyyy-mm-dd format (i.e. not in FME date format), it needs to be parsed first. You can use

@DateTimeFormat(@DateTimeParse(@Value(_date),%Y-%m-%d),%d/%m/%Y

expression to parse and then format your date. There is also DateTimeConverter transformer that will help you avoid writing nested functions :)


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • November 27, 2019

Hi @left65

if the date comes in yyyy-mm-dd format (i.e. not in FME date format), it needs to be parsed first. You can use

@DateTimeFormat(@DateTimeParse(@Value(_date),%Y-%m-%d),%d/%m/%Y

expression to parse and then format your date. There is also DateTimeConverter transformer that will help you avoid writing nested functions :)

My version of FME will format from yyyy-mm-dd without parsing first.

Incidentally, i think in this case it's a date parameter that is displayed as yyyy-mm-dd when you selected but is actually stored as an FME date.