[SCRIPT-HELP]how to access current date and store it

i am trying get the current date in a script im working on. any way of storing it?

if datetime.today == ('2015-11-23', '%Y-%m-%d'):
    layout = self.layout

    row = layout.row(align=True)
   
    row.prop(ob, makecurve,text= "Make Curve")

Can someone help me make this work?

Try this:


import datetime
import time




ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')


print(st)

You can save the value in the scene

Thanks for quick reply!
How would I come about making the “if” statement work?


ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')


print(st)

if st == ('2015-11-23', '%Y-%m-%d'):
    layout = self.layout

    row = layout.row(align=True)
   
    row.prop(ob, makecurve,text= "Make Curve")
else:
    pass

Your problem is that st has a different format string that your if.

Change the format of st to the same of your if:


st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')

okay I tried this, but still nothing…

ts = time.time()

currentday = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
desireddate = datetime.date('2015-11-23')

print(st)
if currentday == desireddate:
    layout = self.layout

    row = layout.row(align=True)
    
    row = layout.row(align=True)
   
    row.prop(ob, makecurve,text= "Make Curve")

Try this:


mport datetime


# Option A
import time
ts = time.time()
current = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')


# Option B
current = datetime.datetime.now().strftime('%Y-%m-%d')


desiredate = datetime.datetime(2015, 11, 23).strftime('%Y-%m-%d')


print(current)


if current == desiredate:
    print("OK")

Or this:


import datetime


current = datetime.datetime.now() 
desiredate = datetime.datetime(2015, 11, 23)


if current.date() == desiredate.date():
    print("OK")

Not near my laptop, but will definitely try it. Thanks for taking time to help me. I’ll let you know if it worked.

Works perfectly. Thank you so much!