johnny-b-goode
johnny-b-goode

Reputation: 3893

How to convert System.DateTime to related amount of minutes?

I need to convert a variable from System.DateTime type to related amount of minutes of integer type E.g.

4:00AM = 240 minutes

(amount of minutes from the beginning of the day to 4:00AM),

12:00 = 720 minutes, 23:00 = 1380 minutes.

Is there any .net utility function?

Upvotes: 0

Views: 51

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460288

You can use TimeSpan.TotalMinutes, you get the timespan from DateTime.TimeOfDay:

DateTime now = DateTime.Now;
int minutes = (int) now.TimeOfDay.TotalMinutes;

Upvotes: 4

Related Questions