Search code examples
c#datetimetimerintervalshour

How to get hours only from a timespan


How do I use only hours from DateTime.Now.ToString() for setting a value (eg: a price) for two or more intervals?

I want to set a variable p differently for every 5 hours.


Solution

  • int p = DateTime.Now.Hour;
    

    MSDN Documentation