Dreamfire Posted August 12, 2008 Share Posted August 12, 2008 Hello everyone, i have a question.I am designing a script around an helpdesk ticket program.There is a string i get from the program that shows the date and time of the created ticket.example: "2-7-2008 1:29:05" (D-M-YYYY H:MM:SS)But it does not show the "ZERO" in front of the "day, month and hour" as you can see in the example.(this by the way only happens if the day, month or hour is below 10)But i need to change its format for sorting purposes to exacly this: "08/07/02 01:29" (YY/MM/DD HH:MM)So when for example the original is "28-11-2007 11:34:26" its needs to become "07/11/28 11:34",that one is easy because day, month, and hour is 10 or above, meaning no "ZERO's" needs to be added.But when the original for example is "5-12-2008 6:48:32" it still needs to become "08/12/05 06:48",you can see why this can be trickyI tryed many things but i cant figure it out, would some of you guys help me.sincerely,Dreamfire Link to comment Share on other sites More sharing options...
bogQ Posted August 12, 2008 Share Posted August 12, 2008 (edited) Hello everyone, i have a question. I am designing a script around an helpdesk ticket program. There is a string i get from the program that shows the date and time of the created ticket. example: "2-7-2008 1:29:05" (D-M-YYYY H:MM:SS) But it does not show the "ZERO" in front of the "day, month and hour" as you can see in the example. (this by the way only happens if the day, month or hour is below 10) But i need to change its format for sorting purposes to exacly this: "08/07/02 01:29" (YY/MM/DD HH:MM) So when for example the original is "28-11-2007 11:34:26" its needs to become "07/11/28 11:34", that one is easy because day, month, and hour is 10 or above, meaning no "ZERO's" needs to be added. But when the original for example is "5-12-2008 6:48:32" it still needs to become "08/12/05 06:48", you can see why this can be tricky I tryed many things but i cant figure it out, would some of you guys help me. sincerely, Dreamfire look in the help file under StringRegExpReplace or StringReplace ;<== edited xD to help you replace - with / to add 0 infront of something look in the help file under StringSplit and StringLen thats my sugestion heare is one exsample #include <Date.au3> $vreme = _DateTimeFormat( _NowCalc(),2) $vreme_1 = StringSplit($vreme, ".") $len = StringLen($vreme_1[1]) if $len = "1" then $vreme_2 = "0"&$vreme_1[1] EndIf if $len <> "1" then $vreme_2 = $vreme_1[1] EndIf $len = StringLen($vreme_1[2]) if $len = "1" then $vreme_3 = "0"&$vreme_1[2] EndIf if $len <> "1" then $vreme_3 = $vreme_1[2] EndIf MsgBox(0,"",$vreme) MsgBox(0,"",$vreme_2&"/"&$vreme_3&"/"&$vreme_1[3]) but im shure that there r better wayes to do this Edited August 12, 2008 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Szhlopp Posted August 12, 2008 Share Posted August 12, 2008 Hello everyone, i have a question.I am designing a script around an helpdesk ticket program.There is a string i get from the program that shows the date and time of the created ticket.example: "2-7-2008 1:29:05" (D-M-YYYY H:MM:SS)But it does not show the "ZERO" in front of the "day, month and hour" as you can see in the example.(this by the way only happens if the day, month or hour is below 10)But i need to change its format for sorting purposes to exacly this: "08/07/02 01:29" (YY/MM/DD HH:MM)So when for example the original is "28-11-2007 11:34:26" its needs to become "07/11/28 11:34",that one is easy because day, month, and hour is 10 or above, meaning no "ZERO's" needs to be added.But when the original for example is "5-12-2008 6:48:32" it still needs to become "08/12/05 06:48",you can see why this can be trickyI tryed many things but i cant figure it out, would some of you guys help me.sincerely,DreamfireRegExp won't help you here. You need to use the 'String" commands found in the help file. =)Help file actually is really awesome in AutoIt. I suggest looking there... RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+' Link to comment Share on other sites More sharing options...
Nahuel Posted August 12, 2008 Share Posted August 12, 2008 Here's my try: $String="5-12-2008 6:48:32" $newstring=_ConvertDate($String) MsgBox(0,"",$newstring) Func _ConvertDate($date) $DateHour=StringSplit($date," ") $SplitDate=StringSplit($DateHour[1],"-") $SplitHour=StringSplit($DateHour[2],":") ;Convert year $SplitDate[3]=StringRight($SplitDate[3],2) ;Convert day If StringLen($SplitDate[1])=1 Then $SplitDate[1]="0" & $SplitDate[1] ;Convert month If StringLen($SplitDate[2])=1 Then $SplitDate[2]="0" & $SplitDate[2] ;Convert hour If StringLen($SplitHour[1])=1 Then $SplitHour[1]="0" & $SplitHour[1] ;Convert minutes If StringLen($SplitHour[2])=1 Then $SplitHour[2]="0" & $SplitHour[2] ;Convert seconds If StringLen($SplitHour[3])=1 Then $SplitHour[3]="0" & $SplitHour[3] Return $SplitDate[3] & "-" & $SplitDate[2] & "-" & $SplitDate[1] & " " & $SplitHour[1] & ":" & $SplitHour[2] & ":" & $SplitHour[3] EndFunc Link to comment Share on other sites More sharing options...
Dreamfire Posted August 12, 2008 Author Share Posted August 12, 2008 (edited) I searched the Helptool in AutoIt completely and all i could come up with is.$time = "23-10-2007 12:16:00" Send($time) $result_222 = StringRegExp($time, "[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{4} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}") If $result_222 = 1 Then MsgBox(0,"","222") Send("{BACKSPACE}") Send("{BACKSPACE}") Send("{BACKSPACE}") Send("{HOME}") Send("{SHIFTDOWN}{RIGHT}{RIGHT}{SHIFTUP}") Send("{CTRLDOWN}x{CTRLUP}{DELETE}") Send("{CTRLDOWN}{RIGHT}{CTRLUP}{LEFT}") Send("/{CTRLDOWN}v{CTRLUP}") Send("{HOME}") Send("{SHIFTDOWN}{RIGHT}{RIGHT}{SHIFTUP}") Send("{CTRLDOWN}x{CTRLUP}{DELETE}{DELETE}{DELETE}") Send("{CTRLDOWN}{RIGHT}{CTRLUP}{LEFT}{LEFT}{LEFT}") Send("{CTRLDOWN}v{CTRLUP}/") Send("{CTRLDOWN}{RIGHT}{CTRLUP}") Send("{END}") EndIf^that is btw only a part of the codeThat works but in a wierd way, and when day and/or month and/or hour are below 10 it wont work all the time.I am no Master in AutoIt, i am only using it for a year or so. Edited August 12, 2008 by Dreamfire Link to comment Share on other sites More sharing options...
Nahuel Posted August 12, 2008 Share Posted August 12, 2008 Using Send() for this kind of things is never recommended. Link to comment Share on other sites More sharing options...
bogQ Posted August 12, 2008 Share Posted August 12, 2008 Here's my try: dont write them compleet solution to problem, show them how its working and let them learn they way to do rest bdw nice to see you Nahuel TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Dreamfire Posted August 12, 2008 Author Share Posted August 12, 2008 (edited) Here's my try:You sir are a true Master, thats works like a charm.I wil examin the code and hope to learn from that.Many thanks EDIT: oops wrong quote Edited August 12, 2008 by Dreamfire Link to comment Share on other sites More sharing options...
Nahuel Posted August 12, 2008 Share Posted August 12, 2008 dont write them compleet solution to problem, show them how its working and let them learn they way to do rest bdw nice to see you Nahuel Yeah, that's true. But I always think that if he's really interested, he'll learn from it. Nice to see you too Glad we could help, Dreamfire Link to comment Share on other sites More sharing options...
Dreamfire Posted August 12, 2008 Author Share Posted August 12, 2008 dont write them compleet solution to problem, show them how its working and let them learn they way to do rest bdw nice to see you Nahuel I must agree with you BogQ, but i do am more happy.I will surely try to learn more about "Functions etc."anyways. thanks guys. thread may be closed. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 12, 2008 Moderators Share Posted August 12, 2008 Hello everyone, i have a question. I am designing a script around an helpdesk ticket program. There is a string i get from the program that shows the date and time of the created ticket. example: "2-7-2008 1:29:05" (D-M-YYYY H:MM:SS) But it does not show the "ZERO" in front of the "day, month and hour" as you can see in the example. (this by the way only happens if the day, month or hour is below 10) But i need to change its format for sorting purposes to exacly this: "08/07/02 01:29" (YY/MM/DD HH:MM) So when for example the original is "28-11-2007 11:34:26" its needs to become "07/11/28 11:34", that one is easy because day, month, and hour is 10 or above, meaning no "ZERO's" needs to be added. But when the original for example is "5-12-2008 6:48:32" it still needs to become "08/12/05 06:48", you can see why this can be tricky I tryed many things but i cant figure it out, would some of you guys help me. sincerely, Dreamfire$s_string = "28-11-2007 11:34:26" $s_converted = _MyCustomTimeDateConversion($s_string) $i_extended = @extended ; Number of replacements made ConsoleWrite("New Format: " & $s_converted & @CRLF & "Number of replacements made: " & $i_extended & @CRLF) Func _MyCustomTimeDateConversion($s_string) Local $a_find_alltimestamps = StringRegExp($s_string, "(\d+-\d+-\d+ \d+:\d+:\d+)", 3) If @error Then Return SetError(1, 0, $s_string) Local $a_sre, $i_replaced For $i = 0 To UBound($a_find_alltimestamps) - 1 $a_sre = StringRegExp($a_find_alltimestamps[$i], "(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)", 1) If @error Then ContinueLoop $a_sre[0] = StringFormat("%02s", $a_sre[0]) $a_sre[1] = StringFormat("%02s", $a_sre[1]) $a_sre[2] = StringTrimLeft($a_sre[2], 2) $a_sre[3] = StringFormat("%02s", $a_sre[3]) $a_sre[4] = StringFormat("%02s", $a_sre[4]) $s_string = StringReplace($s_string, _ $a_find_alltimestamps[$i], _ $a_sre[2] & "/" & $a_sre[1] & "/" & $a_sre[0] & _ " " & $a_sre[3] & ":" & $a_sre[4]) $i_replaced += @extended Next Return SetError(0, $i_replaced, $s_string) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now