Skip to main content
Question

Create a customized DateTime field?

  • Jul 22, 2021 3:50 PM UTC
  • 8 replies
  • 207 views

I am using AttributeCreator to add a new date attribute, and this is what I have in the attribute value:

@DateTimeFormat(@round(@DateTimeNow(localUnzoned),0),%Y-%m-%d %H:%M:%S)

Β 

I am getting an warning and null value in my output:

Β 

I have tried using DataTimeConverter, DatetimeCalculator, and DateTImeStamper. All works, but it doesnt give me the output I want.

Β 

Example: 2021-07-21 10:30:40

Β 

Any suggestion?

Β 

Β 

Β 

8 replies

gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • Jul 22, 2021 8:52 PM UTC

What warning are you getting? Your example works for me without any changes.


  • Author
  • Jul 23, 2021 5:11 PM UTC

What warning are you getting? Your example works for me without any changes.

either an error:

An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt

Β 

or a warning:

Attribute(string) : `fme_expression_warnings{0}.message' has value `Failed to evaluate expression '@DateTimeFormat(20210721171660,%Y-%m-%d %H:%M:%S)'. Result is set to null'


jkr_wrk
Influencer
Forum|alt.badge.img+37
  • Jul 23, 2021 9:33 PM UTC

Works fine here. Maybe try changing the date format of your PC? Just a wild guess.


gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • Jul 24, 2021 12:31 AM UTC

either an error:

An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt

Β 

or a warning:

Attribute(string) : `fme_expression_warnings{0}.message' has value `Failed to evaluate expression '@DateTimeFormat(20210721171660,%Y-%m-%d %H:%M:%S)'. Result is set to null'

the @round function isn't aware it is working on a time so rounds 59.9 seconds to 60 seconds making it an invalid time. Can you get by without that? Maybe truncate after the formatting if you are getting decimal seconds.


jkr_wrk
Influencer
Forum|alt.badge.img+37
  • Jul 24, 2021 12:30 PM UTC

either an error:

An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt

Β 

or a warning:

Attribute(string) : `fme_expression_warnings{0}.message' has value `Failed to evaluate expression '@DateTimeFormat(20210721171660,%Y-%m-%d %H:%M:%S)'. Result is set to null'

Ah, that would be the problem. You could use something like @floor or @left(%S,2)


  • Author
  • Jul 26, 2021 4:33 PM UTC

either an error:

An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt

Β 

or a warning:

Attribute(string) : `fme_expression_warnings{0}.message' has value `Failed to evaluate expression '@DateTimeFormat(20210721171660,%Y-%m-%d %H:%M:%S)'. Result is set to null'

I have taken out the @round, currently is @DateTimeFormat(@DateTimeNow(localUnzoned),%Y-%m-%d %H:%M:%S)Β and now its giving me an error, the same one I shown above. I am not getting any warnings.


  • Author
  • Jul 26, 2021 4:34 PM UTC

Works fine here. Maybe try changing the date format of your PC? Just a wild guess.

error - An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt


gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • Jul 26, 2021 8:17 PM UTC

either an error:

An error occurred while attempting to convert the '' component of a date. A possible reason for this is that the data in the date field may be corrupt

Β 

or a warning:

Attribute(string) : `fme_expression_warnings{0}.message' has value `Failed to evaluate expression '@DateTimeFormat(20210721171660,%Y-%m-%d %H:%M:%S)'. Result is set to null'

Can you break it down into parts. So first put @DateTimeNow(localUnzoned) into an attribute and log what that gives.