Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check the input format of a date python

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

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in validate
ValueError: "Incorrect data format, should be YYYY-MM-DD"
Comment

PREVIOUS NEXT
Code Example
Python :: python bisection method 
Python :: python pandas change column values to all caps 
Python :: create empty csv file in python 
Python :: python blackjack 
Python :: python list of random float numbers 
Python :: python get keypressed value 
Python :: change column name df 
Python :: mape python 
Python :: find sum of values in a column that corresponds to unique vallues in another coulmn python 
Python :: python return right operand if left is falsy 
Python :: how to say someting in python 
Python :: cool advances python ptoject ideas 
Python :: how to add multiple dfs to excel sheet 
Python :: matplotlib random color 
Python :: how to make an encryption program in python 
Python :: start the environment 
Python :: python get words between two words 
Python :: python blueprint 
Python :: how to recurse a function 
Python :: pandas remove prefix from columns 
Python :: Python USD to Euro Converter 
Python :: random name generator in python 
Python :: place a widget in a specific position in tkinter 
Python :: convert from object to integer python 
Python :: image to array keras 
Python :: skewness python 
Python :: python date + days 
Python :: aioschedule python 
Python :: pandas select column by index 
Python :: split imagedatagenerator into x_train and y_train 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =