Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:28:57+00:00 2026-05-11T11:28:57+00:00

Python has pretty good date parsing but is the only way to recognize a

  • 0

Python has pretty good date parsing but is the only way to recognize a datetime such as ‘Today 3:20 PM’ or ‘Yesterday 11:06 AM’ by creating a new date today and doing subtractions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:28:57+00:00Added an answer on May 11, 2026 at 11:28 am

    A library that I like a lot, and I’m seeing more and more people use, is python-dateutil but unfortunately neither it nor the other traditional big datetime parser, mxDateTime from Egenix can parse the word ‘tomorrow’ in spite of both libraries having very strong ‘fuzzy’ parsers.

    The only library I’ve seen that can do this is magicdate. Examples:

    >>> import magicdate >>> magicdate.magicdate('today') datetime.date(2009, 2, 15) >>> magicdate.magicdate('tomorrow') datetime.date(2009, 2, 16) >>> magicdate.magicdate('yesterday') datetime.date(2009, 2, 14) 

    Unfortunately this only returns datetime.date objects, and so won’t include time parts and can’t handle your example of ‘Today 3:20 PM’.

    So, you need mxDateTime for that. Examples:

    >>> import mx.DateTime  >>> mx.DateTime.Parser.DateTimeFromString('Today 3:20 PM') <mx.DateTime.DateTime object for '2009-02-15 15:20:00.00' at 28faa28>  >>> mx.DateTime.Parser.DateTimeFromString('Tomorrow 5:50 PM') <mx.DateTime.DateTime object for '2009-02-15 17:50:00.00' at 2a86088> 

    EDIT: mxDateTime.Parser is only parsing the time in these examples and ignoring the words ‘today’ and ‘tomorrow’. So for this particular case you need to use a combo of magicdate to get the date and mxDateTime to get the time. My recommendation is to just use python-dateutils or mxDateTime and only accept the string formats they can parse.


    EDIT 2: As noted in the comments it looks python-dateutil can now handle fuzzy parsing. I’ve also since discovered the parsedatetime module that was developed for use in Chandler and it works with the queries in this question:

    >>> import parsedatetime.parsedatetime as pdt >>> import parsedatetime.parsedatetime_consts as pdc >>> c=pdc.Constants() >>> p=pdt.Calendar(c) >>> p.parse('Today 3:20 PM') ((2010, 3, 12, 15, 20, 0, 4, 71, -1), 3) >>> p.parse('Yesterday 11:06 AM') ((2010, 3, 11, 11, 6, 0, 3, 70, -1), 3) 

    and for reference here is the current time:

    >>> import datetime >>> datetime.datetime.now() datetime.datetime(2010, 3, 12, 15, 23, 35, 951652) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Program { static void Main(string[] args) { Timer timer… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Use GROUP_CONCAT SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo; May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Your code doesn't work because the function is not returning… May 11, 2026 at 10:50 pm

Related Questions

I started using NetBeans for Python development, and so far it looks pretty good.
I'm developing open source cross-platform platform for non-realtime multiplayer chat/game system. Like card games,
I'm hacking some support for DomainKeys and DKIM into an open source email marketing
I'm working on a project that has to read and manipulate QuickTimes on Windows.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.