search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How do I use a date time after TimeRangeSelectedJavaScript?

Asked by Philip
8 years ago.

In my view I'm using this line to go to another view when I click on a empty date in the DayPilotMonth calendar:

TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime={0}';"

In my controller of this view I have this code:

DateTime startingtime;
if (Request.QueryString["startingtime"] != null)
{
startingtime = Convert.ToDateTime(Request.QueryString["startingtime"]);
startingtime.ToString("yyyyMMdd");
ViewBag.Message = startingtime;
}
else
{
ViewBag.Message = "Error";
}

But when I run the application I get error at the Convert.ToDateTime line.
The following error message pops up: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: String was not recognized as a valid DateTime.

Can someone give me a hint or something? Thanks in advance. :)

Comment posted by Philip
8 years ago.

Bump

Answer posted by Dan Letecky [DayPilot]
8 years ago.

The start of the selection is available in "start" variable in TimeRangeSelectedJavaScript. It is a DayPilot.Date object.

TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime=' + start;"

It will be converted to string using .toString() method which returns ISO 8601 date string.

You can also call .toString() explicity and use a custom format:

TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime=' + start.toString('yyyyMMdd');"

See also:
http://api.daypilot.org/daypilot-date-tostring/

Comment posted by Philip
8 years ago.

Oh man thank you so much it's working now. I have been stuck for so long. Is there anywhere I can read about the objects available for the DayPilotMonth? I haven't really found any information about it.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.