Detect day_of_week, then do something about it

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Detect day_of_week, then do something about it

Post by thegame2010 » 13 Dec 2016, 15:47

Hello again! It's been a long time, and I've finally got one worthy of a post.
I have a piece of code that builds an email for me for work with cookie-cutter pleasantries at the beginning and end. I'm hoping to make it a little less robotic. This is the part giving me issues right now.

Code: Select all

#persistent

FormatTime, datestring,, MM/dd/yyyy
StringSplit, d, TodayDate, /
date := d3 d1 d2
FormatTime, day_of_Week, %date%, dddd
Pleasantry = day!
if (day_of_Week = Tuesday)
	Pleasantry = weekend!
	return
	
#^!z::MsgBox %day_of_Week% %Pleasantry%
This code should say "weekend!" when it's Tuesday ("day!" on all other days) and I press Ctrl + Alt + Win + z. It does not.

In the end, I want one that works just like this:

Code: Select all

#persistent

FormatTime, datestring,, MM/dd/yyyy
StringSplit, d, TodayDate, /
date := d3 d1 d2
FormatTime, day_of_Week, %date%, dddd
Pleasantry = day!
if (day_of_Week = Friday)
	Pleasantry = weekend!
	return
if (day_of_Week = Saturday)
	Pleasantry = weekend!
	return	
#^!z::MsgBox %day_of_Week% %Pleasantry%
In this case it would say "weekend!" on Friday and Saturday, and "day!" on all other days. Any suggestions?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Detect day_of_week, then do something about it

Post by kon » 13 Dec 2016, 16:48

Code: Select all

if (A_WDay > 5)
    Pleasantry := "weekend!"
else
    Pleasantry := "day!"
Or

Code: Select all

Pleasantry := A_WDay > 5 ? "weekend!" : "day!"
All together:

Code: Select all

MsgBox, % A_DDDD " " (A_WDay > 5 ? "weekend!" : "day!")
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Detect day_of_week, then do something about it

Post by thegame2010 » 13 Dec 2016, 17:08

Woah, okay. That's way simpler. I have much more research to do to simplify my code. Thanks all!
Post Reply

Return to “Ask for Help (v1)”