Skip to main content

I'm attempting to use relative dates, however I want to exclude data that was modified "Last Friday" where today is "Monday", however I can't see any documentation at what acceptable relative dates there are and what they actually mean (i.e. if today is Monday, does "Last Monday" return as today or the week before? Or does "next Monday" return as today?)?

I'm not sure what underlying language Safe used to implement this but I suspect if we can pin that down on this thread (with their input @Mark2AtSafe) we can get some docs. Safe don't appear to have an exclusive list anywhere. Here's a couple of resources though @takashi's is more reliable as "Next Sunday" works but "First Sunday Next Month" doesn't:

http://php.net/manual/en/datetime.formats.relative.php

http://fme-memorandum-takashi.blogspot.com/2013/12/datetime-calculation-with-dateformatter.html

One curious discovery I have just made in looking at this is that the new DateTimeConverter doesn't appear to support relative dates, so you have to grab an old DateFormatter from an old Workspace to do this (one attached for you). Not sure why Safe deprecated it, unless I've misunderstood.

Dave

dateformatter.fmw


In my understanding, the old DateFormatter was implemented with the Tcl "clock" command, and the relative time option had been derived from Tcl specifications. Tcl Commands > clock

In FME 2017.1, FME Date/Time Functions have been newly introduced, and the current Date/Time transformers such as DateTimeConverter all are implemented with the FME Data/Time functions. Since FME Date/Time Functions didn't inherit the relative time option, it has retired quietly from the DateTimeConverter.

However, if necessary, you can still use the relative time by calling the Tcl command directly with the TclCaller. See also this thread: FME 2018 natural language dates no longer accepted

OK, so I wanted to get an idea of what functions are used by everyone. The reason is that the DateTimeCalculator now covers a lot of this behaviour.

In "tomorrow, yesterday, today, now, last, this, next, ago" the DateTimeCalculator (or DateTimeStamper) covers tomorrow, yesterday, today, now, and ago.

eg to find "tomorrow" simply fetch today's date (DateTimeStamper) and add one day (DateTimeCalculator).

Or - for example - to find "3 weeks" fetch today's date and add three weeks.

What we don't still cover (as far as I can see) is "next" and "last"; eg "next monday" or "last tuesday" because even if you know what today is, there's no direct way to get a relative date based on the name of the day. You would have to have a little calculation to figure out the difference in days between a Thursday and a Monday, then use the DateTimeCalculator to add that figure to today's date.

So there are workarounds, and for that reason I don't know if this will be a high priority issue. I've asked the developers and will let you know what they say, but I don't think we'll put anything in place very quickly. Best solution might be to create a hub transformer. I'll see what I can do.


OK, @dbryantgeo and others. I created a custom transformer (RelativeDateCalculator) that carries out relative date operations:


  • Today's Date
  • Tomorrow's Date
  • Yesterday's Date
  • Next Day of the Week (eg Next Tuesday's Date)
  • Last Day of the Week (eg Last Tuesday's Date)
  • Next Week's Date
  • Last Week's Date
  • Next Month's Date
  • Last Month's Date
Find it here: https://hub.safe.com/transformers/relativedatecalculator - or through the Workbench Quick Add dialog.I didn't implement "4 day's ago" or "3 week's time" type of functionality, because the published parameters list would get a little too convoluted. In the event we get the ability to customize the GUI a little better, I'll add that behaviour in (although a simple DateTimeCalculator is the easy substitute).Hope you find it helpful

 

Mark


OK, @dbryantgeo and others. I created a custom transformer (RelativeDateCalculator) that carries out relative date operations:


  • Today's Date
  • Tomorrow's Date
  • Yesterday's Date
  • Next Day of the Week (eg Next Tuesday's Date)
  • Last Day of the Week (eg Last Tuesday's Date)
  • Next Week's Date
  • Last Week's Date
  • Next Month's Date
  • Last Month's Date
Find it here: https://hub.safe.com/transformers/relativedatecalculator - or through the Workbench Quick Add dialog.I didn't implement "4 day's ago" or "3 week's time" type of functionality, because the published parameters list would get a little too convoluted. In the event we get the ability to customize the GUI a little better, I'll add that behaviour in (although a simple DateTimeCalculator is the easy substitute).Hope you find it helpful

 

Mark

I just stumbled upon this transformer and it's really helpful. Thanks @mark2atsafe


Reply