How to set a variable to be “Today's” date in Python/Pandas

后端 未结 8 2258
醉话见心
醉话见心 2020-12-23 19:35

I am trying to set a variable to equal today\'s date.

I looked this up and found a related article:

Set today date as default value in the model

Howe

8条回答
  •  被撕碎了的回忆
    2020-12-23 19:56

    You can also look into pandas.Timestamp, which includes methods like .now and .today. Unlike pandas.to_datetime('now'), pandas.Timestamp.now() won't default to UTC:

      import pandas as pd
    
      pd.Timestamp.now() # will return California time
      # Timestamp('2018-12-19 09:17:07.693648')
    
      pd.to_datetime('now') # will return UTC time
      # Timestamp('2018-12-19 17:17:08')
    

提交回复
热议问题