Time stamp conversion

Hi All,

I want to convert timestamp.

Current Format: Tue, 16 Apr 2019 18-30-01 -0400
Expected Format: 2019-04-16 18:30:01

Thanks,
Ashok

if the value is stored in variable like this
in_date_string = “Tue, 16 Apr 2019 18-30-01 -0400”
then the output should be
ou_date_string = Datetime.ParseExact(Split(variable1,",")(1).ToString.Trim.Substring(0,20),“dd MMM yyyy HH-mm-ss”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd HH-mm-ss”)

and it worked buddy
image
Cheers @ashoks93

2 Likes

If it’s already a datetime and you just want a string output to look like the expected format, then you’d use YourDateTime.ToString("yyyy-MM-dd HH:mm:ss)

I am assuming that you want 2 digit days, hours, and minutes (e.g. the 6th of april is 2019-04-06). If you want single digits just change the dd to d, the HH to H, and the mm to m.

See all of the datetime formats here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Thanks for the input Dave!

Thanks @Palaniyappan ! Your solution worked.

1 Like

Great
Cheers @ashoks93

Hi,

I’m getting different error now.

Format: “Tue, 16 Apr 2019 18:30:01 -0400”

image

1 Like

can i have a view on the assign activitty with value and to property
Cheers @ashoks93

1 Like

I just found that single digit date causing the issue.

Test Date: “Tue, 2 Jul 2019 13:52:43 -0400”

Datetime.ParseExact(Split(variable1,",")(1).ToString.Trim.Substring(0,20),“dd MMM yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy:MM:dd HH:mm:ss”)

Thanks,
Ashok

1 Like

The splits and substrings seem to be causing the error and are not needed as it makes the solution quite fragile. You can just provide the datetime format into your DateTime.ParseExact() statement. Utilize the link I provided to tailor it, but I’m guessing it will look like this:

DateTime.ParseExact(YourDateAsString,"ddd, d MMM yyyy HH:mm:ss zzz",System.Globalization.CultureInfo.InvariantCulture)

I am just guessing on that last “zzz” portion though, I’m assuming that’s how far off of GMT your timezone is? Again, utilize the custom string format link I posted above to tailor it to your solution.

1 Like

Fine
Its resolved
kindly have a view on this xaml
timestamp.zip (10.3 KB)
Cheers @ashoks93