Reputation: 2146
In VB.NET I want to get the date in text like Microsoft Excel
eg: In MSExcel entering the date : 01/01/2013 and setting format to text it gives output 41275
How can I do this with vb.net?
Upvotes: 2
Views: 526
Reputation: 18064
Do a date difference
DateDiff(DateInterval.Day, Cdate("01/01/2013"),Cdate("01/01/1900"))-2
OUTPUT:
-41275
DateDiff(DateInterval.Day, Cdate("01/01/1900"),Cdate("01/01/2013"))+2
OUTPUT:
41275
Refer LIVE DEMO
Upvotes: 1
Reputation: 54532
You will want the DateTime.ToOADate Method.
Module Module1
Sub Main()
Dim dt As DateTime = DateTime.Parse("1/1/2013")
Console.WriteLine(dt.ToOADate())
Console.ReadLine()
End Sub
End Module
From above link:
An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.
Upvotes: 2