I have set the date format on the PC to Short Date 11/25/16 when I run this code
the Watch shows;
0: BATCHDATE=DRG11252016
0: CYEAR=2016
0: CDAY=25
0: CMONTH=11
0: TODAY=11/25/16
0: BATCHPRE=DRG
[code]GetDate>today
DatePart>today,M,CMonth
DatePart>today,D,CDay
DatePart>today,Y,CYear
Let>BatchDate=%BatchPre%%CMonth%%CDay%%CYear%
msg>BatchDate[/code]
The resulting variable displays the as 2016
What's wrong with my code?
Year Format not changing
Moderators: Dorian (MJT support), JRL
-
- Pro Scripter
- Posts: 132
- Joined: Mon Dec 22, 2008 4:56 pm
- Location: St Augustine FL
Year Format not changing
Thank you in advance for all your help
Gil
Gil
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Year Format not changing
That's what DatePart does. Returns the full year from a date.
If you just want to remove portions of the short date as is then use MidStr:
Or my preference for total portability would be:
If you just want to remove portions of the short date as is then use MidStr:
Code: Select all
MidStr>today,7,2,yearDigits
Code: Select all
Year>yyyy
MidStr>yyyy,3,2,yy
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 132
- Joined: Mon Dec 22, 2008 4:56 pm
- Location: St Augustine FL
Re: Year Format not changing
Thanks for your response!
When I reviewed the Watch List and saw 0: TODAY=11/25/16, I was expecting the year format to be 16
So If I understand correctly DatePart is not looking at the system Date format for it's results?
When I reviewed the Watch List and saw 0: TODAY=11/25/16, I was expecting the year format to be 16
So If I understand correctly DatePart is not looking at the system Date format for it's results?
Thank you in advance for all your help
Gil
Gil
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Year Format not changing
It wants a valid date format. What a valid date is is somewhat dictated by the system settings. So it DOES look at it, but it is not a substring tool. It still returns a year value. Year values are 4 digits.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 132
- Joined: Mon Dec 22, 2008 4:56 pm
- Location: St Augustine FL