{"id":9642,"library":"dateformat","title":"Dateformat","description":"Dateformat is a small Python library designed for quickly parsing and formatting dates using its own set of intuitive format codes. It wraps standard Python `datetime` objects for convenience. The current version is 0.9.7, with a relatively slow release cadence, last updated in mid-2022.","status":"active","version":"0.9.7","language":"en","source_language":"en","source_url":"https://github.com/stestagg/dateformat","tags":["date","time","formatting","parsing","datetime"],"install":[{"cmd":"pip install dateformat","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"format","correct":"from dateformat import format"},{"symbol":"parse","correct":"from dateformat import parse"},{"note":"dateformat provides its own wrapper around the standard datetime module.","wrong":"import datetime","symbol":"datetime","correct":"from dateformat import datetime"}],"quickstart":{"code":"import dateformat\nimport datetime as std_datetime\n\n# Get a datetime object (can be standard datetime or dateformat.datetime)\nnow_dt = std_datetime.datetime.now()\n\n# Format a datetime object using dateformat's codes\nformatted_date = dateformat.format(now_dt, \"YYYY-MM-DD HH:MM:SS\")\nprint(f\"Formatted: {formatted_date}\")\n\n# Parse a date string using dateformat's codes\ndate_string = \"2023-10-27 14:35:01\"\nparsed_dt = dateformat.parse(date_string, \"YYYY-MM-DD HH:MM:SS\")\nprint(f\"Parsed: {parsed_dt}\")\n\n# Using dateformat's own datetime wrapper\ndf_now = dateformat.datetime.now()\nformatted_df_now = dateformat.format(df_now, \"Do MMMM YYYY\")\nprint(f\"Formatted (df.dt): {formatted_df_now}\")","lang":"python","description":"This example demonstrates how to use `dateformat.format` to convert a `datetime` object (either standard or `dateformat`'s wrapper) into a string, and `dateformat.parse` to convert a string into a `datetime` object, both utilizing `dateformat`'s unique format codes."},"warnings":[{"fix":"Always refer to the `dateformat` documentation for the correct format codes. Convert `%Y` to `YYYY`, `%m` to `MM`, `%d` to `DD`, `%H` to `HH`, `%M` to `II` (for minutes), `%S` to `SS` etc.","message":"Dateformat uses its own custom set of formatting codes (e.g., 'YYYY', 'MM', 'DD', 'HH') which are distinct from Python's standard `datetime.strftime`/`strptime` codes (e.g., '%Y', '%m', '%d', '%H'). Mixing these will lead to `ValueError` or incorrect output.","severity":"breaking","affected_versions":"All versions"},{"fix":"For formatting and parsing with `dateformat`'s codes, always use `dateformat.format(dt_object, format_string)` and `dateformat.parse(date_string, format_string)` respectively. Do not try to call `strftime` or `strptime` directly on `dateformat.datetime` objects with custom codes.","message":"The `dateformat.datetime` object is a wrapper around the standard `datetime.datetime` object. While convenient, direct calls to methods like `strftime()` or `strptime()` on `dateformat.datetime` instances will behave like standard `datetime` objects and will not use `dateformat`'s custom format codes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the project's maintenance status. For actively developed alternatives with similar features, consider libraries like `pendulum` or `arrow`, which may offer more frequent updates and broader community support.","message":"The project has a slow release cadence, with the last stable release (v0.9.7) in July 2022. While functional, users should not expect rapid feature development, bug fixes, or immediate support for new Python versions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Replace standard `%` format codes with `dateformat`'s custom codes. For example, change `%Y-%m-%d` to `YYYY-MM-DD`.","cause":"Attempting to use standard `datetime.strftime`/`strptime` format codes with `dateformat.format` or `dateformat.parse`.","error":"ValueError: Invalid format string: '%Y-%m-%d'"},{"fix":"Always use `dateformat.format(your_datetime_object, 'YYYY-MM-DD')` to apply `dateformat`'s formatting logic. The `strftime` method still exists on the underlying `datetime` object but uses standard `%` codes.","cause":"Trying to directly call `strftime` on a `dateformat.datetime` object or a standard `datetime` object, expecting `dateformat`'s custom formatting logic to apply.","error":"AttributeError: 'datetime.datetime' object has no attribute 'strftime' (when using dateformat.datetime)"},{"fix":"Ensure you are importing correctly as `from dateformat import format, parse` or calling via the main module: `dateformat.format(...)` and `dateformat.parse(...)`.","cause":"Incorrect import: Trying to call `datetime.parser` or `datetime.format` when you meant `dateformat.parse` or `dateformat.format`.","error":"TypeError: parser() takes 2 positional arguments but 3 were given (or similar for format)"}]}