0

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.

1
  • How to add rounded data time to days.
    – Grzegorz Z
    Feb 23, 2013 at 10:27

2 Answers 2

2

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/

2
  • 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, 2013 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, 2013 at 15:48
1

.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.

1
  • 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, 2013 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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