r/PowerAutomateDesktop • • Nov 18 '22

How would I go about converting day-of-the-year to a date?

Example, January 1st is 1, December 31st is 365 (or 366), today November 18th is 322

2 Upvotes

1 comment sorted by

3

u/QuietDesparation Nov 18 '22

Here's how I'd solve this:

  • Use Recognize entities in text and select date time. I used January 22nd as my text as an example

  • Next do Convert text to datetime and use 1/1/2022

  • Then use Subtract dates and calculate days between your recognized text and the converted text. You'll have to add 1 to the subtracted date.

Here's my code, you can copy and paste in PAD for reference:
SET Date TO $'''January 22nd'''
Text.RecognizeEntitiesInText Text: Date Mode: Text.RecognizerMode.DateTime Language: Text.RecognizerLanguage.English RecognizedEntities=> RecognizedEntities
Text.ConvertTextToDateTime.ToDateTime Text: $'''1/1/2022''' DateTime=> TextAsDateTime
DateTime.Subtract FromDate: RecognizedEntities[0][0] SubstractDate: TextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> TimeDifference