Trying to get week day name from a date

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
CZ
Newbie
Posts: 18
Joined: Wed Feb 07, 2007 7:51 am

Trying to get week day name from a date

Post by CZ » Tue Mar 31, 2015 8:18 pm

Hello,
I'm trying to get a week day name for dates. I've searched the forums for the answer, but can't seem to get it. Whenever I run the macro I get "7, Saturday" no matter what date I enter. I would appreciate any help.

Here is my code:

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Dialog>dlgDateMask
object dlgDateMask: TForm
Left = 574
Top = 476
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Date Mask Sample'
ClientHeight = 119
ClientWidth = 299
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Label1: TLabel
Left = 96
Top = 16
Width = 100
Height = 16
Caption = 'Date MM/DD/YY'
end
object MSImage1: tMSImage
Left = 113
Top = 35
Width = 64
Height = 21
end
object Label2: TLabel
Left = 240
Top = 16
Width = 28
Height = 16
Caption = 'Input'
end
object Edit1: TEdit
Left = 113
Top = 35
Width = 64
Height = 24
Enabled = False
NumbersOnly = True
TabOrder = 0
Text = '__/__/__'
end
object Edit2: TEdit
Left = 230
Top = 35
Width = 50
Height = 24
MaxLength = 8
NumbersOnly = True
TabOrder = 1
end
object MSButton1: tMSButton
Left = 113
Top = 80
Width = 64
Height = 25
Caption = 'Ok'
Default = True
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>dlgDateMask
AddDialogHandler>dlgDateMask,MSButton1,OnClick,Process
AddDialogHandler>dlgDateMask,Edit2,OnKeyUp,DateMask
AddDialogHandler>dlgDateMask,MSImage1,OnClick,SetFocusToEdit2
Show>dlgDateMask,res1
SRT>DateMask
If>DateMAsk_Key=37
Press Right
Press Backspace
EndIf
GetDialogProperty>dlgDateMask,edit2,text,datedata
Length>datedata,strlen
If>strlen<8
Let>FinalDate={"FinalDate"}
EndIf
If>strlen=0
Let>datedata=__/__/__
Goto>EndDateMask
EndIf
MidStr>datedata,1,2,mm
If>%mm%>12
Let>mm=12
EndIf
MidStr>datedata,3,2,dd
If>{(%mm%=02)and(%dd%>29)}
Let>dd=29
EndIf
If>{((%mm%=04)or(%mm%=06)or(%mm%=09)or(%mm%=11))and(%dd%>30)}
Let>dd=30
EndIf
If>{((%mm%=01)or(%mm%=03)or(%mm%=05)or(%mm%=07)or(%mm%=08)or(%mm%=10)or(%mm%=12))and(%dd%>31)}
Let>dd=31
EndIf
MidStr>datedata,5,4,yy
If>strlen=1
Let>datedata=%mm%_/__/__
EndIf
If>strlen=2
Let>datedata=%mm%/__/__
EndIf
If>strlen=3
Let>datedata=%mm%/%dd%_/__
EndIf
If>strlen=4
Let>datedata=%mm%/%dd%/__
EndIf
If>strlen=5
Let>datedata=%mm%/%dd%/%yy%___
EndIf
If>strlen=6
Let>datedata=%mm%/%dd%/%yy%__
EndIf
If>strlen=7
Let>datedata=%mm%/%dd%/%yy%_
EndIf
If>{(%strlen%>=6)}
If>FinalDate<>{"FinalDate"}
Let>datedata=%FinalDate%
Else
Let>modres={%yy% mod 4}
If>modres<>0
If>{(%mm%=02)and(%dd%=29)}
Let>dd=28
EndIf
EndIf
Let>datedata=%mm%/%dd%/%yy%
Let>FinalDate=%mm%/%dd%/%yy%
EndIf
EndIf
Label>EndDateMask
SetDialogProperty>dlgDateMask,edit1,text,datedata
END>DateMask
SRT>SetFocusToEdit2
SetDialogObjectFocus>dlgDateMask,Edit2
Press BackSpace
END>SetFocusToEdit2
SRT>Process
GetDialogProperty>dlgDateMask,edit1,text,datedata
Length>datedata,strlen
If>Strlen=8
MDL>datedata
VBEval>Weekday(%datedata%,1),res
VBEval>WeekdayName(%res%,,1),res2
MessageModal>%res%, %res2%
Else
MDL>"%datedata%" is an incomplete or malformed date. Please re-enter
EndIf
END>Process

The part that I am having a problem with is the 6th and 7th line from the bottom of the code. It seems to work fine if I have a specific date in quotes, "03/31/15", but when I try to use a value it isn't showing the correct day.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Trying to get week day name from a date

Post by JRL » Wed Apr 01, 2015 3:34 pm

You need quotes around %datedata%.

VBEval>Weekday("%datedata%"),res
VBEval>WeekdayName(%res%,,1),res2

CZ
Newbie
Posts: 18
Joined: Wed Feb 07, 2007 7:51 am

Re: Trying to get week day name from a date

Post by CZ » Sat Apr 04, 2015 5:51 pm

JRL,

Thank you very much. It's works great. I've been trying to figure this out for quite a while and couldn't do it. Would you mind explaining why the quotes "" are needed. BTW as you probably know I found your Date Mask on the forum search and it is fantastic!!. Thanks again for the help

CZ

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts