Py String To Datetime
30:00' Into a Real Datetime Object
- PYDATETIME
ComfyUI is full of text, and dates are just text until something treats them as dates. Py String To Datetime is that something: it takes a date string and a format string and hands back a real Python datetime object (a PYDATETIME) that the rest of the pack can actually reason about.
The inverse of Py Datetime To String, it's the node you reach for when a date arrives as a string - from a CSV column, a widget, whatever - and you need it as a proper datetime to feed datetime-aware nodes or to format consistently.
How it works
It's datetime.strptime(value, date_format) - Python's string-to-datetime parser. The critical part is date_format: it must describe your string exactly. The default is %Y-%m-%d %H:%M:%S, which parses 2025-03-10 14:30:00. If your string is 2025-03-10 (no time), you need %Y-%m-%d. If it's 03/10/2025, that's %m/%d/%Y. The format codes are the standard Python strptime/strftime table.
This strictness is the whole game. Unlike a lenient human reading "March 10", strptime demands the format match the input character for character, or it raises.
Inputs and outputs
value- the date string to parse.date_format- the strptime format string describing it. Default%Y-%m-%d %H:%M:%S.
Output: a PYDATETIME, which wires into Py Datetime To String for reformatting, or into datetime-capable pandas nodes.
Install
Ships in HowToSD/ComfyUI-Data-Analysis. Manager: search "Data analysis" in the Custom Node Manager, install ComfyUI-Data-Analysis, restart, reload the browser. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
mv ComfyUI-Data-Analysis data-analysis # README: example workflows expect this folder name
pip install -r requirements.txt
No models, no GPU - pure stdlib.
Common issues
Format mismatches are the whole failure surface here, and they're loud: a string that doesn't match the format raises a ValueError, not a silent bad value, so you'll know. Common gotchas: forgetting the time portion when the default format expects it, using %m (month) where you meant %M (minute), and regional formats - %m/%d/%Y is US-style, so a dd/mm/yyyy string needs %d/%m/%Y. And no timezone handling; this is naive datetime. If you're round-tripping through Py Datetime To String, keep the format string identical in both directions.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| value | STRING | — | |
| date_format | STRING | %Y-%m-%d %H:%M:%S | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PYDATETIME | PYDATETIME | — |