Jump to content

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

Time Converting......


  • Please log in to reply
7 replies to this topic
randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
Hello all,

I'm trying to use Titan's "Date parser - convert any date format to YYYYMMDDHH24MISS" module

I'm giving it a variable split from 'stringsplit' which is, specifically,

07/20/2009 09:47:17 AM

And I'm getting a return of

20090722

I can't imagine why the date would be wrong....

timer := DateParse("%actions2%")
msgbox , %timer%

;;date parsing module follows

DateParse(str) {
	static e2 = "i)(?:(\d{1,2}+)[\s\.\-\/,]+)?(\d{1,2}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*)[\s\.\-\/,]+(\d{2,4})"
	str := RegExReplace(str, "((?:" . SubStr(e2, 42, 47) . ")\w*)(\s*)(\d{1,2})\b", "$3$2$1", "", 1)
	If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
		. "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
		. "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i)
		d3 := i1, d2 := i3, d1 := i4, t1 := i5, t2 := i7, t3 := i8
	Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t)
		RegExMatch(str, "i)(\d{1,2})\s*:\s*(\d{1,2})(?:\s*(\d{1,2}))?(?:\s*([ap]m))?", t)
			, RegExMatch(str, e2, d)
	f = %A_FormatFloat%
	SetFormat, Float, 02.0
	d := (d3 ? (StrLen(d3) = 2 ? 20 : "") . d3 : A_YYYY)
		. ((d2 := d2 + 0 ? d2 : (InStr(e2, SubStr(d2, 1, 3)) - 40) // 4 + 1.0) > 0
			? d2 + 0.0 : A_MM). ((d1 += 0.0) ? d1 : A_DD) . t1
			+ (t1 = 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "am" ? 0.0 : 12.0) . t2 + 0.0 . t3 + 0.0
	SetFormat, Float, %f%
	Return, d
}

;end date parsing module

Honestly if I just had something to convert that particular format to AHK format it would work everywhere I need it but I'm not that good at string manipulation....

Any ideas for me? This is the last bit of my program....

THANKS!!! :)

guestx
  • Guests
  • Last active:
  • Joined: --

I'm giving it a variable split from 'stringsplit' which is, specifically,

07/20/2009 09:47:17 AM

And I'm getting a return of

20090722

I can't imagine why the date would be wrong....

If you would read the other posts in that thread, you will see that the original function expects the date in euro format and without seconds. The last version of the function in that thread (posted by alpha) works for your date.
timer := DateParse("07/20/2009 09:47:17 AM") ; = 20090720094717 
msgbox, %timer%
 
DateParse(str) { 
   static e2 = "i)(?:(\d{1,2}+)[\s\.\-\/,]+)?(\d{1,2}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*)[\s\.\-\/,]+(\d{2,4})" 
   str := RegExReplace(str, "((?:" . SubStr(e2, 42, 47) . ")\w*)(\s*)(\d{1,2})\b", "$3$2$1", "", 1) 
   If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?" 
      . "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?" 
      . "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i) 
      d3 := i1, d2 := i3, d1 := i4, t1 := i5, t2 := i7, t3 := i8, t4 := t1 >11 ? "pm" : "am" 
   Else If !RegExMatch(str, "x)^\W*   (\d{1,2}?)   (\d{2})   (\d{2}+)? (?:\s*([ap]m))?  \W*  $", t) 
      RegExMatch(str, "ix)(\d{1,2})  \s*  :  \s*  (\d{1,2})   (?:(?:\s*:\s*) (\d{1,2}))?   (?:\s*([ap]m))?", t) 
         , RegExMatch(str, e2, d) 
   f = %A_FormatFloat% 
   SetFormat, Float, 02.0 
   d := (d3 ? (StrLen(d3) = 2 ? 20 : "") . d3 : A_YYYY) 
      . ((d2 := d2 + 0 ? d2 : (InStr(e2, SubStr(d2, 1, 3)) - 40) // 4 + 1.0) > 0 
         ? d2 + 0.0 : A_MM). ((d1 += 0.0) ? d1 : A_DD) . t1 
         + (((t4 = "pm") && (t1 < 12)) ? +12.0 : 0.0) . t2 +0.0 . t3 + 0.0    ; use this one - defaults to AM 

   SetFormat, Float, %f% 
   Return, SubStr(d,1,4) SubStr(d,7,2) SubStr(d,5,2) SubStr(d,9) 
}


randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
Im sorry guest, I really did a lot of it, I didn't understand a lot of it... I did other searching as well, thanks for your answer and thanks for posting the code for me!!!!! :)

randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
I tried that script and get the same... but it's not the script,

I tried putting my stamp right into the code instead of the variable and I get "20090721143602" for 07/21/2009 02:36:02 PM

However when I use the variable, %actions2%, I get 20092307(SPACES)

I even tried actions2 = %actions2% to trim the string to attempt make sure it's acceptable,

I also tried actions2 without the %% and the result makes me want to shoot myself in the head twice:
Error: the following variable name contains an illegal character:
"07/21/2009 02:36:02 PM" :roll:

I know I'm nubin' it up here, I've tried many other syntax too, what am I doing wrong :?: :?: :?:

MsgBox % DateParse("%actions2%")

I would put more code but I mean, it's just not parsing the string right or something... it doesn't seem to have anything to do with the rest of the code... I didn't think there were variable types like integer, string, etc that would make a difference here. This is just a string from stringsplit...

SKAN
  • Administrators
  • 9105 posts
  • Last active:
  • Joined: 26 Dec 2005
MsgBox % DateParse("%actions2%")
should be
MsgBox % DateParse( actions2 )


randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
Thank you SKAN!!!! :D

randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
Still such a nub...

MsgBox % DateParse( actions2 )

How do I make this store the result in a variable instead of displaying the message box?

I tried searching for code examples but I just don't know how you store the result of a (function call?) to a variable...

Drugwash
  • Members
  • 1065 posts
  • Last active: Yesterday, 11:45 PM
  • Joined: 07 Sep 2008
result := DateParse( actions2 )