Date data types | Python for Beginners [15 of 44]




[ad_1]

As you might expect, you sometimes need to figure out when something will happen. See how Python supports dates

Sample code: https://github.com/microsoft/c9-python-getting-started

Watch the entire series at https://aka.ms/PythonBeginnerSeries

#microsoftdeveloper #pythonforbeginners #learntocode

Source


[ad_2]

Comment List

  • Microsoft Developer
    December 5, 2020

    Thanks ♥

  • Microsoft Developer
    December 5, 2020

    Traceback (most recent call last):

    File "C:/Users/Asus/AppData/Local/Programs/Python/Python38/beginners.py", line 1, in <module>

    current_date = datetime.now()

    NameError: name 'datetime' is not defined

  • Microsoft Developer
    December 5, 2020

    Why are you calling them data?
    They're integers, strings can also be considered data.
    Data is very ambiguous.

  • Microsoft Developer
    December 5, 2020

    It is should be this birthday_date = datetime.strftime(birthday: str, '%d/%m/%y')

    intead of this : birthday_date = datetime.strftime(birthday, '%d/%m/%y')

  • Microsoft Developer
    December 5, 2020

    birthday_date = datetime.strftime(birthday, '%d/%m%y')

    TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'str' object

  • Microsoft Developer
    December 5, 2020

    Python sucks

  • Microsoft Developer
    December 5, 2020

    why when i use %y instead of %Y it gives me error?

  • Microsoft Developer
    December 5, 2020

    from datetime import datetime

    current_date = datetime.now()

    print("Todday is: " + str(current_date))

  • Microsoft Developer
    December 5, 2020

    To input date like – 12/06/2000 – you have to use ('%d/%m/%Y')
    Y – four digits
    To input date like – 12/06/20 – you have to use ('%d/%m/%y')
    y – two digits

  • Microsoft Developer
    December 5, 2020

    The vid starts at 0:00 ur welcome

  • Microsoft Developer
    December 5, 2020

    what can we refer after completion of this course? i want to go for advanced course now.

  • Microsoft Developer
    December 5, 2020

    I'd suggest taking some notes on this lesson and playing around with the datetime function a little to understand it properly since it can be a bit mind numbing if you just gloss over the video and don't take the time to fully understand it.

  • Microsoft Developer
    December 5, 2020

    Hi, i had an error with a highlighted %d . the code won't run

  • Microsoft Developer
    December 5, 2020

    Please help me
    I'm totally new to programming learning python as my first language

    I always get this error:
    ImportError: cannot import name 'datetime' from partially initialized module 'datetime' (most likely due to a circular import)

    It runs fine when I debug and then run it on VScode but debugging shows no errors

  • Microsoft Developer
    December 5, 2020

    microsoft should respond to the problems that coders have in the comments section!

  • Microsoft Developer
    December 5, 2020

    I use Jupyter and it does not work and just blows up

  • Microsoft Developer
    December 5, 2020

    Dont panic….
    Me : too late, my doesn't work

  • Microsoft Developer
    December 5, 2020

    Great tip here: just ditch the "+" plus sign and start to use comma which can avoid the string and integer drama. The plus sign has double meanings: addition in math and go together in space and this is super confusing for Python because Python doesn't know whether you want it to just juxtapose the two string/integer or you want to add them together as two numbers. But if you simply use a comma, well, what else can a comma mean? It only has one meaning: juxtapose the two elements side by side.

  • Microsoft Developer
    December 5, 2020

    May I know, why are you using upper case of Y int the assignment of year. When I used lower case it stopped with error

  • Microsoft Developer
    December 5, 2020

    i get an error when i type it exactly like that:
    raise ValueError("time data %r does not match format %r" %
    line 568 in strptime_datetime
    line 349 in strptime
    '03/22/85' does not match format '%m/%d/y'

  • Microsoft Developer
    December 5, 2020

    learning python in COVID time.

  • Microsoft Developer
    December 5, 2020

    What a coincidence that I am learning this on 1st of March, and yesterday was 29th Feb of a Leap Year !!!

  • Microsoft Developer
    December 5, 2020

    7:00 "Februarry" 😂

  • Microsoft Developer
    December 5, 2020

    import datetime ???
    without it command is not running in vsc .

    import datetime

    current_date = datetime.datetime.now()

    print ('today is :' + str (current_date))

  • Microsoft Developer
    December 5, 2020

    What book would someone recommend to go with these lessons? Dummies or something else?

  • Microsoft Developer
    December 5, 2020

    I am getting a value error when trying to use that strptime method.

    "raise ValueError("unconverted data remains: %s" %

    ValueError: unconverted data remains: 04"

  • Microsoft Developer
    December 5, 2020

    If => timedelta()

    doesnt work try =>>datetime.timedelta()

  • Microsoft Developer
    December 5, 2020

    greetings, I get an error when importing the file datetime.now() shows me
    Traceback (most recent call last):
    File "dates.py", line 4, in <module>
    current_date = datetime.now()
    AttributeError: module 'datetime' has no attribute 'now'

  • Microsoft Developer
    December 5, 2020

    If this prints
    print (datetime.now())
    Then why this doesnt ?
    print (datetime.day())
    Its in the datetime library as well.

  • Microsoft Developer
    December 5, 2020

    in the example date of your birthday: " birthday=date.strptime(current_date, "%d/%m/%y") " If the year we want to introduce is 1919 Phyton interprets it as 2019, why?

  • Microsoft Developer
    December 5, 2020

    L =float(input('Amount borrowed '))

    i =float(input('Interest per annum '))

    n =float(input('Years to payoff '))

    print(type(n))

    print (n)

    M = L(i(1 + i)n)/((1 + i)n-1)

    Why am I getting 'unknown token' regarding the 'n' variable in the last line?

  • Microsoft Developer
    December 5, 2020

    It says date time is not defined. What can I do?

Write a comment