Friday, March 30, 2012

Saving the time with the date

I have a calendar control on a page that is saving the date to a SQL Server 2005 table and this works fine; but how do I also save it with the current time? It is always saving as 12:00:00 AM.

Thanks for the help.

Check your calendar control properties because it probably is setup to display/send only date. In this case SQL server add dfault time for date which is 12 AM.
It should have options like date and time, date only, time only.

Thanks

|||

It seems odd you would use a date from a calendar and want the current time but...

DateTime DateOnly = new DateTime(2007, 5, 3);
DateTime RightNow = DateTime.Now;

// add current time to date

DateOnly = DateOnly.AddHours(RightNow.Hour);
DateOnly = DateOnly.AddMinutes(RightNow.Minute);
DateOnly = DateOnly.AddSeconds(RightNow.Second);

|||

This is an intranet application where our CSRs record incoming items and the time stamp needs to be with the record. I solved it by putting System.DateTime.Now() into a Session variable.

Thanks for the responses. Now if I can figure out my "Access is Denied" problem with ajax...

No comments:

Post a Comment