Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sam Boswell 21 posts 106 karma points
    Jul 29, 2015 @ 16:03
    Sam Boswell
    0

    Date Picker for pre 1900 dates

    Hi Guys,

    I'm trying to store some dates for a historic timeline using the datepicker.

    I've come to the realisation that there are a few limits on this datatype and I'm hoping for some advice on how to remove those limits.

    The first is Umbraco focused: the datepicker element appears to only let me go back as far as 1900-01-01 I'm guessing that there's a validation string somewhere that I can tweak to change this limit?

    The second limit I'm aware of is the datetime datatype in SQL, which is how these dates are stored. Following https://msdn.microsoft.com/en-GB/library/ms187819.aspx I'm aware that the minimum date here is 1753, and this is still not low enough for my use case (1066 onwards)

    Is there a way to make Umbraco use datetime2 as a database format?

    My backup here is to use a textstring for these dates, but that is much more prone to content editor mistakes!

  • Tom C 87 posts 222 karma points
    Oct 15, 2015 @ 10:29
    Tom C
    0

    I discovered this problem last night on 7.2.6 and is still there after upgrading to 7.3.0. Obviously it used to work and can still, as I have dates saved that are pre 1900 from using older versions, but can no longer enter a date before 1900. Is there any quick hack or something that I can do to fix this?

    Thanks a lot for any help anybody could offer?

    Tom

  • Sam Boswell 21 posts 106 karma points
    Oct 15, 2015 @ 10:31
    Sam Boswell
    0

    My bodge for now is to store dates +2000 years.

    eg:

    The date 01-01-760 is entered in the interface as 01-01-2760

    I then subtract 2000 on output.

    Dirty, but it works for now!

  • Tom C 87 posts 222 karma points
    Oct 15, 2015 @ 12:24
    Tom C
    0

    Thanks. That won't work for me as already have hundreds of dates in the correct format!

    There must be some 'fix' for it .. I'll have to look into it further.

  • Aghasi Lorsabyan 2 posts 73 karma points
    Jun 29, 2016 @ 17:52
    Aghasi Lorsabyan
    1

    The date settings applied within Bootstrap Date/time picker widget: https://github.com/Eonasdan/bootstrap-datetimepicker

    It's located in ./Umbraco/lib/datetimepicker directory.

    All you need is to change values of minDate and maxDate properties of $.fn.datetimepicker.defaults object in bootstrap-datetimepicker.js file.

    For instance I need range of dates 1800 - (now + 100 year). Then the $.fn.datetimepicker.defaults object should looks like the following:

    $.fn.datetimepicker.defaults = {
        format: false,
        pickDate: true,
        pickTime: true,
        useMinutes: true,
        useSeconds: false,
        useCurrent: true,
        calendarWeeks: false,
        minuteStepping: 1,
        minDate: moment({y: 1800}),
        maxDate: moment().add(100, 'y'),
        showToday: true,
        collapse: true,
        language: moment.locale(),
        defaultDate: '',
        disabledDates: false,
        enabledDates: false,
        icons: {},
        useStrict: false,
        direction: 'auto',
        sideBySide: false,
        daysOfWeekDisabled: [],
        widgetParent: false
    };
    

    The only problem will occur after the Umbraco update, so better solution is to create Back Office "extension", "plugin", ... I don't know how it's called exactly.

    The code should looks like the following:

    $.fn.datetimepicker.defaults.minDate = moment({y: 1800});
    $.fn.datetimepicker.defaults.maxDate = moment().add(100, 'y');
    

    Aghasi

  • Matthew Hair 4 posts 71 karma points c-trib
    Feb 06, 2019 @ 15:55
    Matthew Hair
    0

    A clean and easy way to implement Aghasi's suggestion is to create a new property editor that inherits from the standard datepicker. Just add a new class to your project, and put code like this in it:

    using Umbraco.Core.PropertyEditors;
    using Umbraco.Web.PropertyEditors;
    
    namespace SedgwickCountyOrg.App_Plugins.HistoricalDatePicker.PropertyEditors
    {
        [PropertyEditor("HistoricalDate", "Historical Date", PropertyEditorValueTypes.Date, "datepicker", Icon = "icon-calendar")]
        public sealed class HistoricalDatePropertyEditor : DatePropertyEditor
        {
            public HistoricalDatePropertyEditor() => DefaultPreValues.Add("minDate", "moment({y: 1800})");
        }
    }
    

    Then you can add a new data type based on the HistoricalDate property editor, and use it in your document types.

Please Sign in or register to post replies

Write your reply to:

Draft