Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Date parser - convert any date format to YYYYMMDDHH24MISS


  • Please log in to reply
94 replies to this topic
ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
I think there's a problem with the handling of AM and PM for 12 O'Clock.

It fails to take into account that 12 am in midnight and 12 pm is noon, not the reverse.

For example:
2:30 am = 200706300230
2:30 pm = 200706301430
Which is correct, but:
12:30 am = 200706301230
12:30 pm = 200706302430
Which is not. 24:30 doens't even exist.

This will be a very useful function if that can be fixed though. I'd try to fix it myself, but your RegEx is way beyond me.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Thanks, I believe it has been fixed in version 1.03.
It was due to a miscalculation in my expressions, not regex ;)

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
I'm afraid I'm still getting wierd results. Now for either "12:30 AM" or "12:30 PM" I'm getting 20070701030 which aside from being wrong for pm, is one too few digits. :( Once again times other than 12 work correctly.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
In 1.04:

12:30 am: 200707010030
12:30 pm: 200707011230
1:30 am: 200707010130
6:37 pm 15 October 2009: 200910151837
12:30: 200707011230 (assumed pm time on it's own)
1:30: 200707011330 (like above)

I hope everything works now.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Works great now! :D

silveredge78
  • Members
  • 499 posts
  • Last active: Mar 14 2014 03:19 AM
  • Joined: 25 Jul 2006
Titan,

Perhaps I was just a bit fried, but I couldn't get it to work for a simple date structure like, 1/1/2007 or 10/21/07. Does this take care of those? It would be great to have an all-inclusive function. :)
SilverEdge78

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
1/1/2007 gives 20070101 which is correct. Your second date has the month and day mixed around, I realize it's the American format but it's not how I implemented my function.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


silveredge78
  • Members
  • 499 posts
  • Last active: Mar 14 2014 03:19 AM
  • Joined: 25 Jul 2006
So 1/1/07 works only because it's the same with the month/day in either position. I imagine then that 1/31/07 would not work. Would you be up for the task for allowing the American variant of date to work using this? Or is that too hard to add in there? I don't know RegEx at all, so when I look at your function, it only makes a little sense.

I ended up making up my own translation thing to use, but it definitely doesn't use RegEx. It uses StringSplit on / and then checks the length of the string to see if it needs a 0 before the day/month.

Thanks for the clarification.
SilverEdge78

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Would you be up for the task for allowing the American variant of date to work using this?

If I did that, British/European formats won't work. Instead you could word the months or use ISO date, i.e. 1st April 2007 or 2007-04-1.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


silveredge78
  • Members
  • 499 posts
  • Last active: Mar 14 2014 03:19 AM
  • Joined: 25 Jul 2006
I would do that happily if I could. I am pulling the data from an SQL database that has the date stored as 10/31/2007 (american). I figured if you tried to account for our version, that it would break the european way. So no worries. But I will see if i can use your script in other things that I do. It is a good script for certain. :)

Ooo...could you make two versions of the script? One for the european and one for the american? Like, v1.4A and v1.4E, where the only difference is that specific date format change.

Just a thought!
SilverEdge78

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Ooo...could you make two versions of the script? One for the european and one for the american?

All you need to do is add the highlighted line before the main function proc.:

DateParse(str) {
	static e2 = "i)(?:(\d{1, ; [...]
[color=violet]	str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})", "$3$2$1")[/color]

Alternatively you can use the same regex before you make the function call.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
How about an optional second parameter, Titan? Something like this:
DateParse(str, sillyFormat = false) {
	if(sillyFormat) { // US locale
		str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})", "$3$2$1")
	}
	// further processing
}
Or, as suggested before, we simply coerce everyone into adopting ISO 8601...

an SQL database that has the date stored as 10/31/2007 (american)

Sounds like a case for The Daily WTF...
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
For such a trivial mod users can refer to the info on this thread. Incorporating it to my official release breaks the simplicity of a single parameter and introduces culture variation dependence which can be complicated given the extra parsing rules, word translations, etc.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


silveredge78
  • Members
  • 499 posts
  • Last active: Mar 14 2014 03:19 AM
  • Joined: 25 Jul 2006
Titan, that is easy for me to do. Thanks for throwing that up here. I don't think it necessary to pass a second parameter. If I'm the first one in a year to offer this up as a concern, I don't think it really is one. As for the formating, perhaps its cause its being exported to CSV? I don't know. I just have to process the file.

Thanks again Titan!
SilverEdge78

empyrean5
  • Guests
  • Last active:
  • Joined: --
I needed to make the following change to make American Date Format mm/dd/yyyy hh:mm.... work:

DateParse(str) {
	static e2 = "i)(?:(\d{1, ; [...]
[color=violet]	str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})(.*)", "$3$2$1$4")[/color]