Link to home
Start Free TrialLog in
Avatar of lavitz
lavitzFlag for Poland

asked on

begin and end of DateTime day

Hi,

Does DataTime have something that allow me from DateTime '2011-02-15 15:44' make end of day?
I yes. How to do it for day, week, month?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you could construct a new datetime value from it's year, month and day values, and add 1 day to that:
http://msdn.microsoft.com/en-us/library/aa326683%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/system.datetime.adddays%28v=vs.71%29.aspx

knowing that 1 day is worth
>= start of day  AND < start of next day
Do you need end of day, or start of next day?
This formula does start of next day:
DATEADD(dd, 1, DATEDIFF(dd, 0, GETDATE()))

Start of next week is:
DATEADD(dd, 8 - DATEPART(dw, getdate()), DATEDIFF(dd, 0, GETDATE()))

Start of next month is:
DATEADD(dd, -DAY(GETDATE()) + 1, DATEADD(mm, 1, DATEDIFF(dd, 0, GETDATE())))
I'm nt sure I understood ur question. Can u rephrase it?
>>'2011-02-15 15:44' make end of day?

From a datetime such as the above do you want to know how much time it is before the next day/week/month ?
Avatar of lavitz

ASKER

from date '2011-01-01 12:14:44' i need end of that day so output should be '2011-01-01 23:59:59'. I know i could do this by adding '23:59:59' but i wonder if .net have such function (and for end of month, year, week)
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial