type system date (YYYYMMDD)

Asked by matthias

I'd like the system date to be typed in the form YYYYMMDD. My first thought was something like that:

year = getYear()
...
type(year + ...)

Any suggestions? =)
Thank you for your help!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Garrett Bartley
Solved:
Last query:
Last reply:
Revision history for this message
Best Garrett Bartley (wgbartley) said :
#1

Give this a try:

from time import strftime
type(strftime("%Y-%m-%d %H:%M:%S"))

You can get more information on the variables at http://docs.python.org/3.1/library/datetime.html?highlight=strftime#strftime-strptime-behavior

Revision history for this message
RaiMan (raimund-hocke) said :
#2

This is correct.

for exactly what you want:
type(strftime("%Y%m%d"))

Revision history for this message
matthias (mpuschmann) said :
#3

Thanks Garrett Bartley, that solved my question.

Revision history for this message
matthias (mpuschmann) said :
#4

Thank you very much for both of your comments!

Revision history for this message
Chili (ben-wong) said :
#5

Hallo I find the following error in my Sikuli IDE, can anyone help^^
[sikuli] [Error] source lineNo: 1
[sikuli] [Error] Traceback (innermost last):
  File "E:\Temp\sikuli-tmp3633998445704413443.py", line 1, in ?
NameError: strftime

Revision history for this message
RaiMan (raimund-hocke) said :
#6

guess you forgot
import time
before you used strftime() (since its line no 1 ;-)

time is the python module, that has to be imported first, to use the contained function strftime()

Revision history for this message
Chili (ben-wong) said :
#7

Hi RaiMan
Thanks your help,
It works as follow^^
import time
popup(time.strftime("%Y%m%d"))

Revision history for this message
RaiMan (raimund-hocke) said :
#8

looking at the row of comments, one get's the impression, that we were testing your ability, to bring things together ;-)
Yeah, you got it.

saying "from time import strftime" namespacing is done by python, so you can simply say strftime().

using only "import time" you have to tell python every time, to look at module time for strftime: time.strftime()

Thanks for your comment and have a nice TIME.

Revision history for this message
Nadesj (nadesj2) said :
#9

I tried to do the same, but it gives me this error:
  File "C:\Users\Nadesj\AppData\Local\Temp\sikuli-tmp7176782465826558881.py", line 15, in <module>
    type(strftime("%Y%m%d"))
NameError: name 'strftime' is not defined

this is how I defined it:
import time
type(strftime("%Y%m%d"))

Revision history for this message
RaiMan (raimund-hocke) said :
#10

@ Nadesj
the import time is nort needed (already done by Sikuli startup)

but you have to write (the module time is there, but you have to tell Python, that strftime is in module time additionally)
type(time.strftime("%Y%m%d"))

or you do it like mentioned in my comment above:
from time import strftime # this tells Python, that strftime comes from module time
type(strftime("%Y%m%d"))

Revision history for this message
Nadesj (nadesj2) said :
#11

Nice, thank you very much, I got it now.
I will have to learn some python before working with sikuli.

Revision history for this message
Nadesj (nadesj2) said :
#12

One problem yet, in the debug part it shows the right date,
in the software where I want it, it gives me this "éà&é&à" instead of 201210.

Revision history for this message
Nadesj (nadesj2) said :
#13

Must be a keyboard problem, i work with an Azerty keyboard.

Revision history for this message
Nadesj (nadesj2) said :
#14

sorry to waste your time, I found the solution in the forum,
I have to use paste. thx and sikuli is super.

Revision history for this message
RaiMan (raimund-hocke) said :
#15

Yes, keyboard problem. type() now only works correctly with the standard qwerty US layout.

use paste() instead - this works.

Besides learning some basic Python (really not much), it is a good idea to just read across the complete guide
http://sikuli.org/trac/wiki/reference-0.10

Revision history for this message
RaiMan (raimund-hocke) said :
#16

No problem.

Wasting time is always a decision and the responsibility of the one who is wasting his time ;-)

So you are always welcome with your questions - but you have to live with the answer or with the fact, that no one answers ;-)