Conrad Jagger
Conrad Jagger

Reputation: 643

Vb.net - Date : How to get start time and end time of the day

How can we accomplish this in vb.net : Get the start of day time and end of day time

For e.g.

Start DateTime: 05-Nov-2013 00:00:00
End DateTime: 05-Nov-2013 23:59:99

Regars

Upvotes: 2

Views: 6348

Answers (3)

dbasnett
dbasnett

Reputation: 11773

My $.02

    Dim someDate As DateTime = DateTime.Now
    Dim StartDateTime As DateTime = someDate.Date
    'last measurable instant for a given date
    Dim EndDateTime As DateTime = someDate.Date.Add(New TimeSpan(TimeSpan.TicksPerDay - 1))

Upvotes: 0

Matt Wilko
Matt Wilko

Reputation: 27322

You can add a TimeSpan to a date value like this:

Dim dateValue As DateTime = DateTime.Now

Dim startTime As DateTime = dateValue.Date + New TimeSpan(0, 0, 0) 'timespan addition not actually needed here
Dim endTime As DateTime = dateValue.Date + New TimeSpan(23, 59, 59)

Upvotes: 3

Tim Schmelter
Tim Schmelter

Reputation: 460058

Dim start As DateTime = yourDate.Date
Dim endTime As DateTime = yourDate.Date.AddDays(1).AddSeconds(-1)

Upvotes: 1

Related Questions