Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python check if string is date format

>>> import datetime
>>> def validate(date_text):
    try:
        datetime.datetime.strptime(date_text, '%Y-%m-%d')
    except ValueError:
        raise ValueError("Incorrect data format, should be YYYY-MM-DD")


>>> validate('2003-12-23')
>>> validate('2003-12-32')

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    validate('2003-12-32')
  File "<pyshell#18>", line 5, in validate
    raise ValueError("Incorrect data format, should be YYYY-MM-DD")
ValueError: Incorrect data format, should be YYYY-MM-DD
Comment

PREVIOUS NEXT
Code Example
Python :: for every file in the folder do python 
Python :: how to check if python has been added to path 
Python :: how to shuffle dictionary python 
Python :: save plot as pdf python 
Python :: get list of folders in directory python 
Python :: python reimport module after change 
Python :: convert column to numeric pandas 
Python :: python subprocess.run output 
Python :: python run server 
Python :: get list of unique values in pandas column 
Python :: linux python installation wheel 
Python :: how to take list of integer as input in python 
Python :: django forms set class 
Python :: how to delete last N columns of dataframe 
Python :: python flask sample application 
Python :: pyqt drag and drop files 
Python :: check if a number is perfect cube in python 
Python :: libGLU.so.1: cannot open shared object file: No such file or directory 
Python :: python open encoding utf-8 
Python :: how to calculate rmse in linear regression python 
Python :: how to save python list to file 
Python :: falsy python 
Python :: python choose random element from list 
Python :: python get how many days in current month 
Python :: tensorflow history plot 
Python :: dataframe copy 
Python :: timestamp to date python 
Python :: remove punctuation from string python 
Python :: pandas series remove punctuation 
Python :: create new django app 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =