Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have got a code:

DateTime dzienStart1;
DateTime dzienStop1;

dzienStart1 = dzienStart.ToLocalTime();
dzienStop1 = DateTime.Now.ToLocalTime().AddMonths(-2).AddDays(-1.0);

Whem I look at a date in debbuger i getting in first date +2 hours. And in secound is good server date:

enter image description here

Please help me.

share|improve this question
    
How to add rounded data time to days. –  Grzegorz Z Feb 23 '13 at 10:27
add comment

2 Answers

My suggestion is to you can do with string format like this...

string DateWithHours = String.Format("{0:yyyy-MM-dd H}", yourDateParameter);

if you round hours then u can manually check by extract minute part from date. if minute is > 30 then add 1 hour to date..

For more details see these links...

http://www.csharp-examples.net/string-format-datetime/

http://mikeinmadison.wordpress.com/2008/03/12/datetimeround/

share|improve this answer
    
I write this code: ` dt = dzienStart; String.Format("{0:yyyy-mm-dd}", dt); item["Dzien"] = dt;`, and i still have got 02:00 Hours. –  Grzegorz Z Feb 24 '13 at 15:14
    
Ok I Can geret I getted 00:00 from this code: ` dt = dzienStart; dtString =String.Format("{0:yyyy-MM-dd}", dt); item["Dzien"] =Convert.ToDateTime(dtString);` –  Grzegorz Z Feb 24 '13 at 15:48
add comment

.Net doesn't have a type for only date without time, but you can get a DateTime with no time set from any DateTime by accessing it's Date property.

If you want to "round" it to the next day if past noon then add 12 hours before getting Date.

share|improve this answer
    
Hello Per, but I always want to take a rounded time, I don't want to adding 12 hours. I always wont to have time 00:00 –  Grzegorz Z Feb 24 '13 at 15:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.