CodeSolved

Solved Programming Questions & Exercises

Review of date format

Practice Easy 939/ Download 1020 Views

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:

2005/05/01
TRUE

2005/13/34
FALSE

11 Answers

This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
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)
Sumy.amiri Download Python
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")

Sumy.amiri Download Python
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 136 Download Python
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)
Behcoder Download Python
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)
Behcoder Download Python
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")
Nima1393 Download Python

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;
}
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close