Python. How to create a Date?

Hello,

I am wondering how to create a date list using numbers of sublists and get a date by sublist with python node.

What have you tried so far?

@ruben.romero ,

import datetime

dt = datetime.date(2023, 2, 12)

OUT = dt

i was more struggeling with the format

1 Like

if you put more commas can you add minutes, seconds, millisecons?

from datetime import date
from datetime import datetime

OUT = datetime.combine(date.today(), datetime.min.time())

i use normal time now with format without separotor @ruben.romero

1 Like

You can see what’s available here.

1 Like

There is a couple of ways to do it and the below indicates these

#Created By Brendan Cassidy

import clr

#Imports date/time info
#See https://docs.python.org/2/library/time.html
from time import gmtime, strftime
#Applying time Day-Month-Year at Hour:min
time_info1=strftime("%d %b %Y at %H:%M", gmtime())

#     OR

#See https://docs.python.org/2/library/datetime.html
from System import DateTime
time_info2=DateTime.Now

OUT = time_info1,time_info2
2 Likes

I tried it but I need datetime.date and datetime.min.time as I want to feed with year,month,day and hour,minute,second with specific number that I got, I do not want to know the date of now.

It worked using only datetime.date(year,month,day) but datetime.combine does not work for unknow reason, this is the warning:

import datetime
from datetime import date
from datetime import datetime

year=2022
month=3
day=12
hour=10
minute=1
second=43
date = datetime.combine(datetime.date(year,month,day),datetime.min.time())

but it worked more simple like that:

import datetime

year=2022
month=3
day=12
hour=10
minute=1
second=43

date = datetime.datetime(year,month,day,hour,minute,second)