FormatTime | ddd | showing day isn't working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fohrums
Posts: 8
Joined: 07 Sep 2018, 05:39

FormatTime | ddd | showing day isn't working

02 Oct 2018, 05:37

# SPECIFICATION

Code: Select all

autohotkeyahk_1.1.30
win10_home_1803.17134.285
I'm unable to show Weekday when using FormatTime (see below for example). I actually run this short ahk-code on another computer that's Win7 and it appears without problem. But, on my win10 machine it doesn't recognize it.

Code: Select all

!+2::
  FormatTime, datetime,, yyyyMMdd@HHmmss-ddd
  SendInput %datetime%
  Return
## PROBLEM:

* Date Formats aren't recognized and only Time Formats are recognized. What would cause this to happen?
+ If I were to use the script it'll output 20181002@053900-ddd when it should be 20181002@053900-TUE (notice the appending weekday)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FormatTime | ddd | showing day isn't working  Topic is solved

02 Oct 2018, 05:45

This is the problem:
FormatTime - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/FormatTime.htm
If Format contains date and time elements together, they must not be intermixed. In other words, the string should be dividable into two halves: a time half and a date half. For example, a format string consisting of "hh yyyy mm" would not produce the expected result because it has a date element in between two time elements.
Here is a workaround. Cheers.

Code: Select all

!+2::
  datetime := A_Now
  FormatTime, ddd, % datetime, ddd
  FormatTime, datetime, % datetime, yyyyMMdd@HHmmss-
  SendInput, % datetime ddd
  return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ThewarII
Posts: 49
Joined: 01 Oct 2014, 09:33

Re: FormatTime | ddd | showing day isn't working

02 Oct 2018, 12:51

Thanks Jeeswg.
That also i want to say.
Or you also don't realy need use datetime := A_Now
Because you use current time.

Code: Select all

!+2::
FormatTime, ddd,, ddd
FormatTime, datetime,, yyyyMMdd@HHmmss-
SendInput, % datetime ddd
Return
I :superhappy:(happy) when I know about AHK.
I have & am using AHK to do anything in windows microsoft.
The first time, I know it in around year 2013.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FormatTime | ddd | showing day isn't working

02 Oct 2018, 13:02

- Hello ThewarII. What you say is true, however, if you use the approach that doesn't store the variable, and you run the script at midnight, you could get a mismatch.
- These situations are unlikely, but they do happen and are avoidable. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
fohrums
Posts: 8
Joined: 07 Sep 2018, 05:39

Re: FormatTime | ddd | showing day isn't working

03 Oct 2018, 05:32

jeeswg wrote:This is the problem (link to from FormatTime - Syntax & Usage | AutoHotkey):
https://autohotkey.com/docs/commands/FormatTime.htm
If Format contains date and time elements together, they must not be intermixed. Here is a workaround:

Code: Select all

!+2::
  datetime := A_Now
  FormatTime, ddd, % datetime, ddd
  FormatTime, datetime, % datetime, yyyyMMdd@HHmmss-
  SendInput, % datetime ddd
  return
I'd say that it was an easy mistake to not have seen this :think: Thank-You jeeswg for you're explanation and input aswell :bravo:
I would however love to see the weekday in all caps but my attempt doesn't work (i've inserted the StringUpper line):

Code: Select all

  datetime := A_Now
  FormatTime, ddd, % datetime, ddd
  FormatTime, datetime, % datetime, yyyyMMdd@HHmmss-
  StringUpper, datetime, datetime
  SendInput, % datetime ddd
  return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FormatTime | ddd | showing day isn't working

03 Oct 2018, 06:30

For upper case. 2 variants. Cheers.

Code: Select all

!+2::
  datetime := A_Now
  FormatTime, ddd, % datetime, ddd
  FormatTime, datetime, % datetime, yyyyMMdd@HHmmss-
  SendInput, % datetime Format("{:U}", ddd)
  return

;!+2::
  datetime := A_Now
  FormatTime, ddd, % datetime, ddd
  StringUpper, ddd, ddd
  FormatTime, datetime, % datetime, yyyyMMdd@HHmmss-
  SendInput, % datetime ddd
  return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ThewarII
Posts: 49
Joined: 01 Oct 2014, 09:33

Re: FormatTime | ddd | showing day isn't working

03 Oct 2018, 12:50

jeeswg wrote:- Hello ThewarII. What you say is true, however, if you use the approach that doesn't store the variable, and you run the script at midnight, you could get a mismatch.
- These situations are unlikely, but they do happen and are avoidable. Cheers.
hello, why you say that?
It also use automatic get current time like A_Now without put it in.
It only difference it get 2 times of time in very little time of second time.
And with your hand put hotkey, it's very long time of that time.
That I understand.
I :superhappy:(happy) when I know about AHK.
I have & am using AHK to do anything in windows microsoft.
The first time, I know it in around year 2013.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FormatTime | ddd | showing day isn't working

03 Oct 2018, 13:38

- The date can change between running the two FormatTime lines. This might seem minor, but it's an avoidable bug. Perhaps a daylight-saving time change could still cause an error in my script.
- The same principle, retrieving the date multiple times and hoping it will still be the same, can have more severe side effects depending on the situation.
- This fails quite regularly for example: A_Now A_MSec. As does this: A_Hour ":" A_Min ":" A_Sec.
combining date variables is unreliable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36338
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ThewarII
Posts: 49
Joined: 01 Oct 2014, 09:33

Re: FormatTime | ddd | showing day isn't working

03 Oct 2018, 13:56

jeeswg wrote:- The date can change between running the two FormatTime lines. This might seem minor, but it's an avoidable bug. Perhaps a daylight-saving time change could still cause an error in my script.
- The same principle, retrieving the date multiple times and hoping it will still be the same, can have more severe side effects depending on the situation.
- This fails quite regularly for example: A_Now A_MSec. As does this: A_Hour ":" A_Min ":" A_Sec.
combining date variables is unreliable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36338
oh your script is longer than you showed in there
It's okay.
You need use store variables.
I :superhappy:(happy) when I know about AHK.
I have & am using AHK to do anything in windows microsoft.
The first time, I know it in around year 2013.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, scriptor2016 and 277 guests