Review of date format
Write a program to format to format yyyy/mm/dDReceive from the user and check whether the date received in the correct format is correct.
Example:
Write a program to format to format yyyy/mm/dDReceive from the user and check whether the date received in the correct format is correct.
Example:
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
import jdatetime
year = int(input("entry your year:"))
month = int(input("enter your month:"))
day = int(input("entter your day:"))
x = jdatetime.date.fromgregorian(year = year , month = month , day = day)
print(x)
date1 = jdatetime.date.today()
print(date1)
if x == date1:
print(True)
if x != date1:
print(False)
year = int(input("entry your year:"))
month = int(input("enter your month:"))
day = int(input("entter your day:"))
print(f"{year}:{month}:{day}")
if month > int(12) and day > int(31):
print("tarikh dar fomat eshtebah ast")
else:
print("tarikh dar format dorosh ast")
import re
from datetime import datetime
def is_valid_date(date_string):
# Review of date format using Regex
pattern = r'^\d{4}/\d{2}/\d{2}$'
if not re.match(pattern, date_string):
return False
# Convert the history of history to the Datetime object and examine the accuracy of history
try:
year, month, day = map(int, date_string.split('/'))
datetime(year, month, day)
return True
except ValueError:
return False
def main():
date_input = input("تاریخ را به فرمت yyyy/mm/dd وارد کنید: ")
is_valid = is_valid_date(date_input)
print(is_valid)
if __name__ == "__main__":
main()
user_date = input("Please enter date: (format: yyyy/mm/dd)")
lst_date = user_date.split("/")
if 0 < int(lst_date[1]) <= 12 and 0 < int(lst_date[2]) <= 31:
print(True)
else:
print(False)
from datetime import datetime
user_date = input("Please enter date: (format: yyyy/mm/dd)")
try:
datetime.strptime(user_date, "%Y/%m/%d")
print (True)
except :
print (False)
year = int(input("year: "))
month = int(input("month: "))
day = int(input("day: "))
format_ymd = f"{year}/{month}/{day}"
if year > 2025:
print(f"History : {format_ymd} year error")
print("False")
elif month > 12:
print(f"History : {format_ymd} month error")
print("False")
elif month > 30:
print(f"History : {format_ymd} day error")
print("False")
elif year < 2025 and month < 13 and day < 31:
print(f"History : {format_ymd}")
print("True")
else:
print("Not")
The format (yyyy/mm/dd) is controlled by the moon and day.
#include <iostream>
using namespace std ;
int main() {
string date ;
cout << "Enter date (yyyy/mm/dd) : " ;
cin >> date ;
string y = date.substr(0,4);
string m = date.substr(5,2);
string d = date.substr(8,4);
int year = stoi(y);
int month = stoi(m);
int day = stoi(d);
bool flag ;
if (y.length() == 4 && m.length() == 2 && d.length() == 2) {
flag = true ;
}
if (flag && 0 < month <= 6 && 0 < day <= 31 ) {
cout << "True" << endl;
} else if (flag && 6 < month <= 12 && 0 < day <= 30) {
cout << "True" << endl;
} else {
cout << "False" << endl;
}
return 0;
}
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.