1

I want to determine the date format of an input datetime64[ns] value, and obtain a str.

Example:

input value = 1978-07-06

output value = '%Y-%m-%d'

I've tried this but got stuck:

import dateutil.parser
from datetime import datetime

yourdate = dateutil.parser.parse(input)
datetimeobject = datetime.strptime(yourdate,'%Y-%m-%d  %H:%M:%S')

Any help on this would be appreciated. Note: dateinfer gave me "No module named 'infer' " error

1 Answer 1

0

extract the date, from input using regular expression

import dateutil.parser
from datetime import datetime

input = '1978-07-06' # or - 06/07/1978
date_obj = dateutil.parser.parse(input)
date_string = date_obj.strftime('%Y-%m-%d %H:%M:%S')
Sign up to request clarification or add additional context in comments.

1 Comment

I'm looking for the strftime format as the output. Also the input date format could change to something like 06/07/1978. What I want to determine is the format based on any given input value ( 06/07/1978 or 1978-07-06). The datatype of input value is datetime64[ns] and not string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.