Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
datetime.datetime.now
#1
i want to import the datetime.datetime.now function, only.  how can i do that?  i still don't understand the package module system.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It's a method, belonging to the datetime type, which belongs to the module. From what I can tell, methods can't be imported.
Reply
#3
ok so i have to do:

import datetime
now=datatime.datatime.now
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Or:
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2017, 1, 10, 10, 37, 51, 289957)

>>> from datetime import datetime as dt
>>> dt.now()
datetime.datetime(2017, 1, 10, 10, 38, 0, 770687)
Pendulum the best date library for Python.
>>> from pendulum import now
>>> now()
<Pendulum [2017-01-10T11:02:07.852108+01:00]>

>>> now = now('Europe/Paris')
>>> now
<Pendulum [2017-01-10T11:02:24.693479+01:00]>
>>> now.in_timezone('America/Toronto')
<Pendulum [2017-01-10T05:02:24.693479-05:00]>

>>> now.is_weekday()
True
>>> now = now.add(days=4)
>>> now.is_weekday()
False
>>> if now.is_weekend():
...     print('Party!')
...     
Party!
Reply
#5
Je vous remercie beaucoup!
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  datetime module question jacksfrustration 10 1,606 Jan-12-2024, 04:54 AM
Last Post: deanhystad
  subtract 2 datetime string jss 4 703 Oct-19-2023, 02:42 PM
Last Post: Larz60+
  discrepancy with datetime with timezone XJia 3 710 Sep-03-2023, 02:58 PM
Last Post: deanhystad
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 1,901 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Trying to delete rows above a specific datetime value cubangt 19 11,001 May-09-2022, 08:57 PM
Last Post: deanhystad
  Problem with datetime [SOLVED] AlphaInc 3 2,543 Apr-22-2022, 01:33 PM
Last Post: snippsat
  How to get evenly-spaced datetime tick labels regardless of x-values of data points? Mark17 4 5,092 Apr-04-2022, 07:10 PM
Last Post: Mark17
  2-dataframe, datetime lookup problem Mark17 0 1,214 Jan-27-2022, 01:02 AM
Last Post: Mark17
  Filter dataframe by datetime.date column glidecode 2 4,910 Dec-05-2021, 12:51 AM
Last Post: glidecode
  How to get datetime from numeric format field klllmmm 3 1,956 Nov-06-2021, 03:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020