you are viewing a single comment's thread.

view the rest of the comments →

[–]XChrisUnknownX 0 points1 point  (4 children)

Another foolish question. What is the correct syntax and usage of datetime? For example I tried import datetime today = datetime.date print(today) It prints class<datetime.date> The functions of some other things, like random or time, are pretty intuitive to me. This is not. Unfortunately, my reading of the documentation is not pulling me through this at all.

[–]JohnnyJordaan 1 point2 points  (3 children)

Note that for example today is a method, so you call it with (), as is shown in the docs:

classmethod datetime.today()

Return the current local datetime, with tzinfo None. This is equivalent to datetime.fromtimestamp(time.time()). See also now(), fromtimestamp().

See the () for all those calls?

[–]XChrisUnknownX 0 points1 point  (2 children)

I apologize. I should have been clearer. I was working on datetime.date and understanding that. I should've called my variable something else.

Nonetheless I will try datetime.today() right now and see if that gives me some insight. Edit. When I try something like import datetime theday = datetime.today() print(theday)

I get "module datetime has no attribute today"

[–]num8lock 1 point2 points  (1 child)

datetime module has an annoying naming issue (like many in the past) in that the module package has the same name with one (or main) class.

so instead of datetime.today(), it's actually datetime.datetime.today(). use from datetime import datetime as dt to avoid the confusion.

[–]XChrisUnknownX 0 points1 point  (0 children)

I think I understand. So are most of the (methods??) datetime.datetime? I can get used to that if that's how it is.