Convert number to date

Hi all,

What is the simplest way to do the following conversion:

2019091 = 01/03/2019
2019121 = 01/04/2019
2019152 = 01/05/2019

The pattern of the above is that the first 4 numbers = YYYY and the last 3 = Total days past in YYYY.
I want to convert the first number string/number to a date with the format DD/MM/YYYY.

Cheers!

@LarsFeilberg

Try this:

Str = “2019091”

Int32 year = Cint(Str.substring(0,3))

Int32 days = Cint(Str.substring(4,Str.Length))

requiredDate = new DateTime(year, 1, 1 ).AddDays(days).ToString(“dd/MM/yyyy”)

2 Likes

Thank you very much!

I’ll try it right away and return with a status soon :slight_smile:

Cheers!

1 Like

Hey Vickydas,

What do you exactly mean by withdrawn and flagged?

Im kind of new here, so please bear with me.

/Lars

@LarsFeilberg

When we delete our posted post that time this will come. It will be deleted automatically in 24 hours. nothing to do with this anything.

1 Like

I have withdrawn my post and i have 24 hours to revoke it.if i have posted something not good for the forum or against the forum guidelines others can flag that post.After 24 hours it’ll be deleted

Nothing to worry about please ignore that post :slight_smile:

1 Like

Ahh, that makes alot of sence. Sorry about the confusion.

1 Like

hello @lakshman

I tried this code and it works good and properly accoding to the condition you have specified but as you can see @LarsFeilberg wants something like this

He wants date of a month back
So @LarsFeilberg use this code
NewDateTime(2019,1,1).AddDays(91).AddDays(-1).AddMonths(-1).ToString(“dd/MM/yyyy”)

If you have created the workflow as suggested by @lakshman than just make minor changes
Inplace of 2019 input the year variable and in place of 91 add Days Variable

2 Likes

Hi again,

For some reason i get an error when trying to create a substring using str.length as the length parameter.

I’m defining days as = Cint(str.Substring(4,str.Length))

Can you explain to me why is is?

I have done the following work around:

days = Cint(right(str,3))

With this work around and with @vickydas requiredDate value it works like a charm.

Thanks you very much for the help both @vickydas & @Iakshman :slight_smile:

1 Like