invalid date syntax with ajax calendar - asp.net

I had Ajax calendar and when I selected from it it give me date as (07/12/2010)
and when I made space between the year and / it converted to (2010/07/12) and this invalid date so pleas what the error.

That's not a error is it? It sounds to me like the Ajax is just setting the date as a culture invariant. See this article on CodeProject

Try Specifying the date Format by using calendar Format property to "dd/MM/yyyy"
http://www.ajaxlines.com/ajax/stuff/article/aspnet_ajax_calendarextender_and_validation.php
Check out http://www.ama3.com/anytime/

If you are working from JS you would be better off working from its numeric (epoch) representation and then convert it to whatever format you want to use or use the js date api to achieve what you want.
https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date

Related

how do I format datetimepicker values properly in ISO 8601 Format

I'm kinda stuck here while adding events in google calendar, everything so far has gone in right way except this, when I am inserting a new event using datetimepicker for date and time the google calendar displaying me wrong date and time for the event.
Since, Google Calendar uses ISO 8601 Format so I guess if I can able to convert the date and time I'm getting into ISO 8601 format then my problem would be resolved. Need help from you guys..
Thank you :)
well, finally got my answer my own and it's quite easy to convert just few line of code.
$tzname=$_POST['tzname'];
$endDate = strtotime($endDate);
$dt= new DateTime("#$endDate");
$googleEventTime = new DateTimeZone($tzname);
$googleendevent=$dt->format('c');
then you pass this $googleendevent into google calendar event array. :)

How can i Convert the DatePicker Input to string

I am using the following Codes to get the date from the date picker
objDD_ml.EffDate=(DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput).ToString
But it does not return the date... It returns like 'DateInput'
How can i use the code to get the value for Effdate as a correct format of date
Anyone please help me..
Whenever you want date into string and in specific format you can always apply following :
objDD_ml.EffDate = (
DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput
).ToString("dd/MM/yyyy")
Try to cast the FindControl object into the corresponding ASP control externally. Then access the value of that control and convert it to .ToString
I don't know what control you are using, but it should be something like below -
objDD_ml.EffDate = ((RadDatePicker)(drv.Cells[i].FindControl("rdpEffDate")).SelectedDate.Tostring;

ASP.NET AJAX toolkit MaskEditExtender Date autocomplete mask

I'm using the asp.net ajax toolkit maskeditextender to mask a textbox for date input. Problem is, though, I can't get it to validate against the date they enter properly. If I turn off autocomplete mask and they type 7 slash 6 slash 88 it will fill in "07/06/88" which, funny enough, is not a valid date. If I autocomplete the mask it should autocomplete to "07/06/1988" but it autocompletes to "07/06/0088" even though I set the century to 1900...
Any advice?
My Solution:
So, autocomplete is terrible. You'd probably have to write some JS to put a 19 in front of the YY because it just appends 00. So you get "07/06/0088"...
As the answerer suggested I turned autocomplete off but it would still not validate the date right. I was using a compare validator against the date datatype. But as it turns out it needs a very specific format:
"07/06/1988"
and nothing else. So, I wrote a custom validator that padds zeros to the month and day and 19 to the year. Also, when I used the txt box's value I had to replicate the same fix to get it convert to datetime without throwing an exception.
I've seen this issue before and there are a few differnet fixes. Are you setting the MaskType to "Date" or "None"? If you're using Date, you may need to write some custom code to autocomplete with the correct digits. If you're using None, you should be able to force the four-digit year which will effectively eliminate the autocomplete issue. This is probably the route that I'd suggest you go becasue you can still restrict the input to digits and validate the input as a date, but you dont have to worry about it autocompleting the wrong century.

How can i validate date?

In a page i have taken a textbox used to enter date in mm/dd/yyyy formate.
I want that when user enter the incorrect format of the date then it show a message that incorrect format of date.
How can i validate textbox that only correct fomate of date can be entered by user.
Thanks in advance..
Instead of validating use calender control or there are loads of Jquery calenders, google it , Its better to provide user with date selection instead of date insertion. Make it idiot proof.
If Not IsDate(txtDate.Text) Then
'Error message code here...
End If
You could also use Date.TryParse().
Use DateTime.TryParseExact method.
DateTime dateValue;
if (DateTime.TryParseExact(textBox.Text, "mm/dd/yyyy",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
{
}

DateTime syntax reference

I understand there are no complete reference docs available for Razor as yet, but would like to know what the various date format options are. Such as:
DateTime.Now.Day
DateTime.Now.Month
DateTime.Now.Year
DateTime.Now.Date
DateTime.Now.TimeOfDay
DateTime.Now.AddDays(1)
etc etc
Is there a complete reference anywhere for DateTime?
How do I get just DD/MM/YYYY without 00:00:00 being appended for example?
The DateTime class is part of the .NET framework. See MSDN documentation.
To format dates, you can use the .ToString(string format) method:
#DateTime.Now.ToString("dd/MM/yyyy")
DateTime is actually a .NET type. The full documentation is available here: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
For your particular question you would want to use the ToShortDateString() method:
DateTime.Now.ToShortDateString()

Resources