Custom date format with jQuery validation plugin

You can create your own custom validation method using the addMethod function. Say you wanted to validate “dd/mm/yyyy”: $.validator.addMethod( “australianDate”, function(value, element) { // put your own logic here, this is just a (crappy) example return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/); }, “Please enter a date in the format dd/mm/yyyy.” ); And then on your form add: $(‘#myForm’) .validate({ … Read more

Given a DateTime object, how do I get an ISO 8601 date in string format?

Note to readers: Several commenters have pointed out some problems in this answer (related particularly to the first suggestion). Refer to the comments section for more information. DateTime.UtcNow.ToString(“yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz”); Using custom date-time formatting, this gives you a date similar to 2008-09-22T13:57:31.2311892-04:00. Another way is: DateTime.UtcNow.ToString(“o”); which uses the standard “round-trip” style (ISO 8601) to give you … Read more

Convert DataFrame column type from string to datetime

The easiest way is to use to_datetime: df[‘col’] = pd.to_datetime(df[‘col’]) It also offers a dayfirst argument for European times (but beware this isn’t strict). Here it is in action: In [11]: pd.to_datetime(pd.Series([’05/23/2005′])) Out[11]: 0 2005-05-23 00:00:00 dtype: datetime64[ns] You can pass a specific format: In [12]: pd.to_datetime(pd.Series([’05/23/2005′]), format=”%m/%d/%Y”) Out[12]: 0 2005-05-23 dtype: datetime64[ns]