Select to view content in your preferred language

Date Picker Help

3709
6
08-04-2011 07:55 AM
gabrielvazquez
Deactivated User
I am attempting to replicate the below date picker example, however I continue to recieve the same errors.  N

http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm

However I continue to have issues with the following lines of code:
  _myTimeExtent.Start = StartDate.SelectedDate;
  _myTimeExtent.End = EndDate.SelectedDate;

The error reads:
Cannot implicitly convert type 'System.DateTime?' to System.DateTime'.

Not sure if this is the bext example to work with when trying to implement a datepicker to query a layer, but this is the only I could find. Has anyone had success implementing this example or can someone share how to implement a date query using a datepicker.
0 Kudos
6 Replies
AndrewChapkowski
Esri Regular Contributor
DateTime? means the object can be nullable, so you need to do an extra step to get the value:

DateTime? dateOrNull = myCalendar.SelectedDate; 
if (dateOrNull != null) 
{     
     DateTime newSelectedDate = dateOrNull.Value; 
} 


Here is a MSDN reference: http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx

Enjoy
0 Kudos
gabrielvazquez
Deactivated User
I was having issues with your code.
I actually did the following, however its not working. I am not recieving any errors, but I believe its not communicating or outputting the data.

_myTimeExtent.Start = DateTime.Parse(StartDate.SelectedDate.ToString());
_myTimeExtent.End = DateTime.Parse(EndDate.SelectedDate.ToString());


However I am wondering now if something like this would be better accomplished using a querytask.
0 Kudos
JMcNeil
Deactivated User
gabriel,

Have you tried using FIDDLER to moniter your ouput and input?  I think Jennifer Link once posted some instruction on how to use fiddler so if you search the forums for fiddler you might find it.  Either way just download it and make sure to have the webforms tab pressed and the textView tab pressed and in the webforms window you will see the request you send to the server and in the textview window you will see the response from the server.

I am attempting to replicate the below date picker example, however I continue to recieve the same errors. N

http://help.arcgis.com/en/webapi/sil.../api_start.htm


That link takes me to start page of the API ref so I'm not entirely sure what you are trying to do or the example you are trying to write but I have linked the mircosoft date picker up with the query task

This date picker
http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html

you can download all of mircosoft code here:
http://silverlight.codeplex.com/

You can use the query but you might have to reformat the date coming from the pick to match your SDE or Geodatabase format.  Something like this

query.Where = string.Format((To_Date(ENTRYDATE, 'YYYY-MM-DD HH24:MI:SS') between To_Date('{0}','MM/DD/YYYY HH:MI:SS AM') and To_Date('{1}','MM/DD/YYYY HH:MI:SS AM')), beginDate.SelectedDate, EndDate.SelectedDate);

J
0 Kudos
gabrielvazquez
Deactivated User
J,
Thank you for info and the links. I will defenitely try the silverlight examples and the code you provided. The API I was trying link was for the DatePickerStyle Property. If you type that it in the API search, you should find easily. Thanks again for the info.
0 Kudos
gabrielvazquez
Deactivated User
I went back and tried to create a  single date query using a datepicker, and it doesnt seem to be working. So I thought I would check the ArcGIS Server Layer the query is using.

I can query the layer through the services directory/ rest/services, however  I have to query the layer using the following format  "111559680000" to recieve a result. I've also found a few older threads linked to this.

http://forums.arcgis.com/threads/20426-Did-the-date-format-change-for-Query-REST-Post-JSON-responses...

http://forums.arcgis.com/threads/16644-Date-Conversion-Problems-REST-lt-gt-Silverlight?highlight=Sil...

I can also obtain a result through the rest services using the where query -  example: "IncidentDate" = '2008-08-31 00:00:00'

I am guessing I have to do some conversion, similar to below. However if anyone has any additional examples it would help. Thanks.

http://msdn.microsoft.com/en-us/library/cc165448.aspx
0 Kudos
gabrielvazquez
Deactivated User
Was able to get the query working using a date picker, by applying the following code to the query task.

DateTime fromdate=Convert.ToDateTime(FromDate.SelectedDate);
DateTime todate =Convert.ToDateTime(ToDate.SelectedDate);

query.TimeExtent=new ESRI.ArcGIS.Client.TimeExtent(new DateTime(1970, 1, 4, 0, 0, 0), new DateTime(1971, 4, 12, 0, 0, 0));

query.TimeExtent=new ESRI.ArcGIS.Client.TimeExtent(fromdate,todate);
0 Kudos