Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vb. NET Convert a date to number

Tags:

vb.net

I have this code in VB . NET

dim date_e As DateTime
date_e = New DateTime(CLng(Convert.ToDouble("635434240520170000")))

The result is:

12.08.2014 07:07:32

Now my question is how i can reverse that encoding to obtain the number from a specific date and time witch i input myself: Lets' say.

22.09.2014 07:07:32

Thank you!

like image 380
Gherghina Ionut-Valentin Avatar asked Sep 30 '22 05:09

Gherghina Ionut-Valentin


1 Answers

The DateTime constructor that takes a Long are the ticks since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.

You just need to parse the string to Date first, then you can use it's Ticks property:

Dim dt = Date.Parse("22.09.2014 07:07:32") ' presumes that this is the correct format
Dim ticks As Long = dt.Ticks

If the input date-string is in a different format than your current culture you can use Date.Parse with the correct culture:

dt = Date.Parse("22.09.2014 07:07:32", New CultureInfo("de-DE"))

or - if you don't know the culture but only the format - Date.ParseExact:

dt = Date.ParseExact("22.09.2014 07:07:32", "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture)
like image 170
Tim Schmelter Avatar answered Oct 05 '22 10:10

Tim Schmelter