How to change multiple Date formats in same column?

I like lubridate for its ease of use: library(lubridate) # note added ugly formats below data <- data.frame(initialDiagnose = c(“14.01.2009”, “9/22/2005”, “4/21/2010”, “28.01.2010”, “09.01.2009”, “3/28/2005”, “04.01.2005”, “04.01.2005”, “Created on 9/17/2010”, “03 01 2010”)) mdy <- mdy(data$initialDiagnose) dmy <- dmy(data$initialDiagnose) mdy[is.na(mdy)] <- dmy[is.na(mdy)] # some dates are ambiguous, here we give data$initialDiagnose <- mdy # mdy … Read more

How to format date in angularjs

Angular.js has a built-in date filter. demo // in your controller: $scope.date=”20140313T00:00:00″; // in your view, date property, filtered with date filter and format ‘MM/dd/yyyy’ <p ng-bind=”date | date:’MM/dd/yyyy'”></p> // produces 03/13/2014 You can see the supported date formats in the source for the date filter. edit: If you’re trying to get the correct format … Read more

Javascript Thousand Separator / string format [duplicate]

Update (7 years later) The reference cited in the original answer below was wrong. There is a built in function for this, which is exactly what kaiser suggests below: toLocaleString So you can do: (1234567.89).toLocaleString(‘en’) // for numeric input parseFloat(“1234567.89”).toLocaleString(‘en’) // for string input The function implemented below works, too, but simply isn’t necessary. (I … Read more

How to print a string at a fixed width?

I find using str.format much more elegant: >>> ‘{0: <5}’.format(‘s’) ‘s ‘ >>> ‘{0: <5}’.format(‘ss’) ‘ss ‘ >>> ‘{0: <5}’.format(‘sss’) ‘sss ‘ >>> ‘{0: <5}’.format(‘ssss’) ‘ssss ‘ >>> ‘{0: <5}’.format(‘sssss’) ‘sssss’ In case you want to align the string to the right use > instead of <: >>> ‘{0: >5}’.format(‘ss’) ‘ ss’ Edit 1: As … Read more

How to parse date string to Date? [duplicate]

The pattern is wrong. You have a 3-letter day abbreviation, so it must be EEE. You have a 3-letter month abbreviation, so it must be MMM. As those day and month abbreviations are locale sensitive, you’d like to explicitly specify the SimpleDateFormat locale to English as well, otherwise it will use the platform default locale … Read more