Code Monkey home page Code Monkey logo

Comments (7)

sisyphsu avatar sisyphsu commented on September 7, 2024

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

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

from dateparser.

VladShyrokyi avatar VladShyrokyi commented on September 7, 2024

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.

from dateparser.

VladShyrokyi avatar VladShyrokyi commented on September 7, 2024

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";

from dateparser.

sisyphsu avatar sisyphsu commented on September 7, 2024

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

from dateparser.

primeap avatar primeap commented on September 7, 2024

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

from dateparser.

akash-yadagouda avatar akash-yadagouda commented on September 7, 2024

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.

from dateparser.

VladShyrokyi avatar VladShyrokyi commented on September 7, 2024

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.

from dateparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.