Is It Possible that DatePart does not work with dd-MMM-yy?

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

Post Reply
KenHadley
Junior Coder
Posts: 28
Joined: Thu Jul 14, 2011 5:02 pm

Is It Possible that DatePart does not work with dd-MMM-yy?

Post by KenHadley » Thu Aug 22, 2013 9:10 pm

I am trying to write a date-format independent macro. The following code works with every date format that I set on Windows 7, with the exception of dd-MMM-yy. With that format set in the Regional Settings, the code blows up on DatePart with the message: "Bad Date Format in DatePart"

Code: Select all

GetDate>today
DatePart>today,D,strDay
mdl>strDay

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1414
Joined: Sun Nov 03, 2002 3:19 am

Post by Dorian (MJT support) » Sat Aug 24, 2013 12:00 am

Hi Ken,

Is this question answered in your other thread?

http://www.mjtnet.com/forum/system-inde ... t7922.html

KenHadley
Junior Coder
Posts: 28
Joined: Thu Jul 14, 2011 5:02 pm

Post by KenHadley » Sat Aug 24, 2013 3:03 pm

Parsnipnose3000 wrote:Hi Ken,

Is this question answered in your other thread?

http://www.mjtnet.com/forum/system-inde ... t7922.html
I don't think it is answered, but perhaps I am confused. If I take, Parsnipnose3000, your code from the other thread:

Code: Select all

//Use YYYY,MM,DD
datelocal>2013,12,31,EndScrapingAtThisDate
//See what it looks like
mdl>%EndScrapingAtThisDate%
then I will end up with EndScrapingAtThisDate containing the last day of 2013 in the "local" setting. That much is clear.

If that local setting, i.e., the Region date-format setting of the Windows 7 OS is set to dd-MMM-yy, then EndScrapingAtThisDate contains: 31-Dec-13. That is also clear.

But now, if I try to use DatePart on this variable, I get the error message I listed at the beginning of this thread.

If I use the exact same example above, but have previously set the Region date-format setting to something *other* than dd-MMM-yy, the code works fine.

So, it seems like DatePart does not work with the "local" setting of dd-MMM-yy. This is what I would like someone else to confirm.

Thank you,

Ken

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Aug 25, 2013 9:03 am

I can confirm same results here. Notably that date format was not in my list of choices in Control Panel and I had to go to advanced settings to override it to get that date format.

DatePart should cope with all "standard" and common settings but it can't work with everything and I guess this is one of them.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

KenHadley
Junior Coder
Posts: 28
Joined: Thu Jul 14, 2011 5:02 pm

Post by KenHadley » Mon Aug 26, 2013 9:26 pm

Marcus Tettmar wrote:I can confirm same results here. Notably that date format was not in my list of choices in Control Panel and I had to go to advanced settings to override it to get that date format.

DatePart should cope with all "standard" and common settings but it can't work with everything and I guess this is one of them.
Not sure what you mean, Marcus. There have always been seven different short date formats. You can set "Additional" formats, but this is not necessary for dd-MMM-yy, which is already there. Shouldn't DatePart work with all seven?

Ken

An example of the seven default ones can be seen in this screen shot:
http://acctgtech.wordpress.com/2011/06/ ... ay-format/

This article shows that these seven go back at least to Windows NT 4.0:
http://support.microsoft.com/kb/241671

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 26, 2013 9:34 pm

I can only report what I see. dd-MMM-yy wasn't an option for me.

DatePart is using Delphi functions - basically "inheriting" Delphi functionality. So I need to check with them - maybe it's a bug in Delphi - or maybe we can find a workaround. Hard to say at present as its 10.30pm here on a public holiday. I need to open up "the box" and look inside, but I'm nowhere near it right now. I've made a note to investigate.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

KenHadley
Junior Coder
Posts: 28
Joined: Thu Jul 14, 2011 5:02 pm

Post by KenHadley » Tue Aug 27, 2013 6:16 pm

Marcus Tettmar wrote:I've made a note to investigate.
Thank you for looking at it further, Marcus. Oddly, I have always assumed this is the "normal" European format. My EU clients use this and claim "it is the only unambiguous date format to use for global applications," since the month is spelled out. Go figure.

Ken

KenHadley
Junior Coder
Posts: 28
Joined: Thu Jul 14, 2011 5:02 pm

Added to 14.0.14 Update

Post by KenHadley » Tue Sep 24, 2013 12:07 am

Marcus,

I noticed that you have added new date formats to DatePart, etc. in the latest update.

I have to say that the service and response with your product is just excellent.

Thank you so much,

Ken

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