Calendar & time problem

J

Jeff

Hey

ASP.NET 2.0

I've got 2 Calendars on a webpage I'm developing. These Calendards are named
"calFrom" and "calTo".. The user will choose from and to date and then
perform some operation based on the chosen dates.

The problem is that the time is set to 00:00:00 both Calendar.SelectedDates.
For "From" the 00:00:00 time is what I want. But for the "To" calendar it
should be the max time for a day (23:59:59)

I've tryed to add 1 day to the from date and then subtract 1 millisecond,
but this don't seem to work

Any suggestions on how to fix this will be greatly appreaciated :)

Jeff
 
J

Jeff

I don't store the values in the database first... I have table containing
many rows, each row has a datetime column and I use these calendars to
choose which dates the sql-select should use in the where-clause

okay here is some code:
command.Parameters.AddWithValue("@start", calFrom.SelectedDate);
dtTo.AddDays(1);
dtTo.AddMilliseconds(-1);
command.Parameters.AddWithValue("@end", dtTo);

or
command.Parameters.AddWithValue("@start", calFrom.SelectedDate);
command.Parameters.AddWithValue("@end", calTo.SelectedDate);

both code examples give the calTo.SelectedDate <selected date> <00:00:00>,
instead it should be <selected date><23:59:59>

Any suggestions?
 
M

Mark Rae [MVP]

okay here is some code:
command.Parameters.AddWithValue("@start", calFrom.SelectedDate);
dtTo.AddDays(1);
dtTo.AddMilliseconds(-1);
command.Parameters.AddWithValue("@end", dtTo);
Any suggestions?

Simple debugging would have told you the answer...

Put a breakpoint on the dtTo.AddDays(1) line and you'll see that the value
of dtTo doesn't change...

DateTime dtTo = calTo.SelectedDate;
dtTo = dtTo.AddDays(1);
dtTo = dtTo.AddSeconds(-1);
command.Parameters.AddWithValue("@end", dtTo);

Or even just:

command.Parameters.AddWithValue("@end",
calTo.SelectedDate.AddDays(1).AddSeconds(-1));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top