How do I process a date that is input by the user and store it in the database in a date field? The date is entered by the user using a jquery datepicker in a text field.
Here are specific needs I have:
1. How do you convert a mm/dd/yy string (the jquery picked can produce any format) to a format storable in the database as a date field.
2. How to get the date and then change it to something like “Wednesday, Aug 11, 2009”?
I’m using C# for the backend, but I should be able to understand VB Code as well.
Thanks!
use
DateTime.Parse(string)to parse the string to aDateTimewhich can then be saved as aDateTimein the database. You may want to use TryParse as suggested in other answers, to ensure that the supplied string can be parsed to aDateTime.To return a DateTime in a certain format, you can call .ToString() on the DateTime and supply a format or use one of the pre-defined formats e.g.
ToShortDateString()