Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

begin and end of DateTime day

Posted on 2011-02-15
6
Medium Priority
?
518 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:lavitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34899539
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
0
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 34899565
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())))
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34899566
I'm nt sure I understood ur question. Can u rephrase it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34899630
>>'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 ?
0
 

Author Comment

by:lavitz
ID: 34899703
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)
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 34899979
Well, since the end of the day (to my knowledge) is always, always, always 23:59:59 you could just use the .Year, .Month and .Day components of your starting date and pass'em to the constructor for a new DateTime with 23:59:59 hard-coded for the time portion.

DateTime testDate = DateTime.Parse("2011-01-01 12:14:44");

DateTime endOfDay = new DateTime(testDate.Year, testDate.Month, testDate.Day, 23, 59, 59);

Open in new window


Or use just the Date portion of testDate, add one day, then subtract one second:
DateTime testDate = DateTime.Parse("2011-01-01 12:14:44");

DateTime endOfDay = testDate.Date.AddDays(1).AddSeconds(-1);

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question