DateTimePicker icon indicating copy to clipboard operation
DateTimePicker copied to clipboard

Date Format with Forward-Slashes

Open matthew-kerle opened this issue 9 years ago • 3 comments

When you add a date format that contains forward slashes, which is a very common formatting in the United States for formatting dates, it breaks. I assume that the code is written only to handle hyphens (-) in dates, but this is super inconvenient. Any quick way to get this added in at least in our implementation? Not sure where to look.

matthew-kerle avatar Dec 11 '15 21:12 matthew-kerle

I now see that you do have a construct option to change the separating character. I'm curious why you can't just format a timestamp without having to specify that. I also need to be able to set this on a per-input level using data- attributes. How would I go about adding the separator options as attributes on each node?

matthew-kerle avatar Dec 11 '15 21:12 matthew-kerle

  • You can achieve this using Locale-specific date separators If you want dateSeparator to be locale-specific, you can set dateSeparator, dateFormat and dateTimeFormat in locale files. For example, you want "/" as a date separator, so you can set it in "DateTimePicker-i18n-en-US.js" file as -
dateSeparator: "/",

dateFormat: "MM/dd/yyyy",
dateTimeFormat: "MM/dd/yyyy HH:mm"

But this will be global, the same date separator should be used for all fields.

  • It is possible to add data attribute for separator settings. There are five separator fields - dateSeparator, timeSeparator, timeMeridiemSeparator, dateTimeSeparator, monthYearSeparator. Can you list fields for which data attribute should be added? Since there was no such requirement these data attributes were not added.

nehakadam avatar Dec 12 '15 05:12 nehakadam

To fix this issue, I removed dateSeparator: "/" from DateTimePicker.js and assigned it using below:

jQuery(document).ready(function(){
    jQuery("#dtBox").DateTimePicker({
            dateSeparator: "/", dateFormat: "MM-dd-yyyy"
        });
  });

yanike avatar Jul 25 '16 22:07 yanike