Mark
Mark

Reputation: 13

Insert fixed current date and time in python

How could I insert a current date and time into a specified location? For example, somewhere in a text or a column in a table. In addition, the result would be a group which cannot be modified.

I use the following string on a button as I click it but it only works on the specified textbox in a form I create. I want the date and time to be freely inserted at anywhere I specify.

import datetime
aaa=datetime.datetime.now().strftime ("%Y-%m-%d %H:%M:%S")
ActiveForm.Controls["GroupBox1"].Controls["TextBox4"].Text = aaa

Example Image

Upvotes: 0

Views: 668

Answers (1)

Fujiao Liu
Fujiao Liu

Reputation: 2253

you could see the official doc to learn more.

>>> import time
>>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
'2017-06-30 11:55:12'
>>> type(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
<type 'str'>
>>> 

Upvotes: 1

Related Questions