Skip to content

Get date format #14

Open
Open

Description

@VladShyrokyi

Hi,
I would like to be able to get the date format from a string. For example, one could add a getFormatPattern method to get a format string that can be used further for business logic.
My case:
I am doing a csv parser, I need to be able to define the data type in a column, this library could help me if it had this function.

Activity

  1. sisyphsu commented on Jul 1, 2021

    @sisyphsu
    Owner

    It's possible, dateparser could detect the format of a date string, internally.

    But, the format detected is regex, is it what you want?

  2. VladShyrokyi commented on Jul 4, 2021

    @VladShyrokyi
    Author

    Not really, need a standard according to https://www.w3.org/TR/NOTE-datetime. So that format can be reused with other libraries, possibly in other languages. For example, when the back end processes a csv document, it sends the converted data with format information that the front end processes with their libraries.

  3. VladShyrokyi commented on Jul 4, 2021

    @VladShyrokyi
    Author

    Example to use:

    var date = "1994-11-05 13:15:30";
    var dateFormat = DateParserUtils.parseFormat(date);
    assert dateFormat = "YYYY-MM-DD hh:mm:ss";

    var date = "1994-11-05";
    var dateFormat = DateParserUtils.parseFormat(date);
    assert dateFormat = "YYYY-MM-DD";

    var date = "11-05-1994 13:15:30";
    var dateFormat = DateParserUtils.parseFormat(date);
    assert dateFormat = "DD-MM-YYYY hh:mm:ss";

    var date = "11-05";
    var dateFormat = DateParserUtils.parseFormat(date);
    assert dateFormat = "DD-MM";

    var date = "04 Jul 2021 19:59:09";
    var dateFormat = DateParserUtils.parseFormat(date);
    assert dateFormat = "DD MMM YYYY hh:mm:ss";

  4. sisyphsu commented on Jul 6, 2021

    @sisyphsu
    Owner

    There has too many formats supported in dateparser, I don't think it's a good idea to use it like this.

  5. primeap commented on Sep 14, 2022

    @primeap

    Hi @sisyphsu ,

    lets say we have csv file .... we want to format a date column .... we can improve performance if we know date format

    so can we get date format

    thanks

  6. akash-yadagouda commented on Sep 15, 2022

    @akash-yadagouda

    I was about to start implementing the code to get the date format given the date string.

    Then I stopped because there are some test cases which are making trouble.

    1. 11/11/2022
      Is it in DD/MM/YYYY format or MM/DD/YYYY?

    Its better to have or follow the date/time format in a project where we are defining these.

  7. VladShyrokyi commented on Sep 15, 2022

    @VladShyrokyi
    Author

    You can declare precedence for formats.

    When somebody passes one string to the method, you check a list of formats by precedence.
    If need to find a format for the string list need create another method for this case. Although, format check logic can be reused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions