Skip to content
This repository has been archived by the owner. It is now read-only.

Datetimepicker sometimes resets to 12/31/1899 12:00 AM #207

Open
nunosilva800 opened this issue Feb 3, 2014 · 11 comments
Open

Datetimepicker sometimes resets to 12/31/1899 12:00 AM #207

nunosilva800 opened this issue Feb 3, 2014 · 11 comments

Comments

@nunosilva800
Copy link

@nunosilva800 nunosilva800 commented Feb 3, 2014

I'm using datetimepicker but I do not want to pick the minutes.
I've set minView to 1 but the minutes still appear as something other than 00.
What I did then was set the format string to "mm/dd/yyyy HH:00 P". All good except for when the user clicks outside the picker without specifying a new date.

I've created a fiddle so you can try it:
http://jsfiddle.net/onumis/MgxeR/5/

It uses your latest JS and CSS, Twitter Bootrap 2.3.2, and jQuery 1.10.1.
(Note that my JS code is at the bottom)

Am I doing something wrong or is it the library that is not parsing/incompatible with the provided format string?

@ChrisEdson

This comment has been minimized.

Copy link

@ChrisEdson ChrisEdson commented Feb 18, 2014

This seems to happen to me whenever I use the meridian (am / pm), especially when I use a space between the minutes and am/pm. No consistency to reproduce though.

@nunosilva800

This comment has been minimized.

Copy link
Author

@nunosilva800 nunosilva800 commented Feb 19, 2014

Updated:
http://jsfiddle.net/MgxeR/6/

Got it working for this very specific case, it might have broken something, but from my 5 minute manual testing, all is fine.

I've changed the update function (line 465 on the fiddle):

                if (typeof date == 'string' || date instanceof String) {
                  date = date.replace(/^\s+|\s+$/g,'');
                }

to

                if (typeof date == 'string' || date instanceof String) {
                  date = new Date(date.replace(/^\s+|\s+$/g,''));
                }

I noticed the problem was that DPGlobal.parseDate could not parse the date (as a string, with the given format), and ended up setting date to new Date(0, 0, 0, 0, 0, 0, 0).
This function is quite confusing, so I'll leave the hard work to someone else ;)

@ChrisEdson

This comment has been minimized.

Copy link

@ChrisEdson ChrisEdson commented Feb 21, 2014

Hmm. This gives me errors. Glad it worked for you though!

If I get any time I might do a pull and see if I can fix the whole thing...

@jonginn

This comment has been minimized.

Copy link

@jonginn jonginn commented Apr 29, 2014

I'm continuing to get this error - and the fix above only breaks the plugin entirely.

It seems to entirely come down to the format, and sometimes switches to 1899 if you activate the dropdown, and click away, and sometimes only switches when you select a date.

Any format without a time breaks it and sets it to 1899 as the plugin cannot parse the date. This is quite annoying, as I had hoped to use this one plugin to enable both date and datetime usage to save on code.

Ex:

$('input.date[data-range="single"]').datetimepicker({
    minView: 2,
    format: 'dd-mm-yyyy',
    startDate: new Date,
    autoclose: true,
  });

Breaks. But:

$('input.date[data-range="single"]').datetimepicker({
    minView: 2,
    format: 'dd-mm-yyyy HH:ii p',
    startDate: new Date,
    autoclose: true,
  });

Works perfectly. The same can also be done by removing the space between i and p - if the format is HH:iip then it also gets confused when no date is selected.

I think a lot of this can be simplified by only running the date through the parser for output when a date has actually been selected, NOT when the user clicks off the dropdown.

joemsak added a commit to joemsak/foundation-datetimepicker-rails that referenced this issue Sep 14, 2014
@ma077146

This comment has been minimized.

Copy link

@ma077146 ma077146 commented Mar 3, 2015

I was having a similar problem. If I re-clicked the control I added after I set the date and time, I was set to year 1899 after that.

My original format was yyyy-mm-dd HH:ii:00 P.

I removed the space between the time and Postmeridian, like so: yyyy-mm-dd HH:ii:00P, and now everything seems to be working find. I can re-click the field and change values as long as I wish to.

@hay-wire

This comment has been minimized.

Copy link

@hay-wire hay-wire commented Sep 20, 2016

@ma077146 solution worked for me! 👍

@abcbaby

This comment has been minimized.

Copy link

@abcbaby abcbaby commented Sep 26, 2017

I had to tweak the parseDate function in boostrap-datetimepicker.js to make it work properly.
Currently the date is set to:

date = new Date(0, 0, 0, 0, 0, 0, 0), // which is Dec. 31, 1899

change to:

date = new Date(), // which is today's date
@AusDude

This comment has been minimized.

Copy link

@AusDude AusDude commented Dec 28, 2017

I also had this issue and it was certainly annoying.
I needed to ensure that all date formats that were being fed to the input control, as well as any dates being returned from datetimepicker were all formatted exactly the same way. For me, given my locale I used "dd/mm/yyyy HH:ii".

This format was also replicated on the SQL Query which was used to initially supply the stored date:
CONVERT(VARCHAR(10), tblAppointment.StartDateTime, 103) + ' ' + CONVERT(VARCHAR(5), tblAppointment.StartDateTime, 108) AS StartDateTime)

@oprearocks

This comment has been minimized.

Copy link

@oprearocks oprearocks commented May 4, 2018

We also encountered a similar issue on our project, and we fixed it without touching the plugin code. I wrote about it here: https://oprea.rocks/blog/bootstrap-datetimepicker-reset

Just skip past my crude storytelling and go to the middle of the article where the actual solution is explained.

@proximadata

This comment has been minimized.

Copy link

@proximadata proximadata commented May 14, 2018

Can't make it work. I want my datetime to be shown as like 14 May 2018 7:12pm
If I use this format "dd M yyyy HH:ii" it works but as soon as I add "p" by the end it resets to weird 1899 date.

@oprearocks

This comment has been minimized.

Copy link

@oprearocks oprearocks commented May 21, 2018

@proximadata That's probably because it's unable to parse your time properly. What does your full format look? Besides "HH:ii" you probably have your timezone... you need to separate it with a space, I believe, from the time, so the library can properly parse that format.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.