Autoit Date reformatJava string to date conversionGetting Python and AutoIT to work together using win32com: what's up with those window handles?GUICtrlCreateDate set date in autoitConvert date string (EST) to Java Date (UTC)Convert an integer to a 2 byte Hex value in PythonCall functions in AutoIt DLL using Python ctypesAssign contents of Excel cell to string variable in AutoITHow do I convert one date format into another date format in Java?How do you get ONE variable to equal multiple lines of a .txt file in AutoIt?from “21 marzo 2017” to Unix timestamp
Why is Collection not simply treated as Collection<?>
Why are electrically insulating heatsinks so rare? Is it just cost?
Were any external disk drives stacked vertically?
Neighboring nodes in the network
Assassin's bullet with mercury
What is the word for reserving something for yourself before others do?
Can I ask the recruiters in my resume to put the reason why I am rejected?
How do conventional missiles fly?
What is the most common color to indicate the input-field is disabled?
How can I make my BBEG immortal short of making them a Lich or Vampire?
Emailing HOD to enhance faculty application
How to take photos in burst mode, without vibration?
Facing a paradox: Earnshaw's theorem in one dimension
How much of data wrangling is a data scientist's job?
Stopping power of mountain vs road bike
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
Twin primes whose sum is a cube
Anagram holiday
Why doesn't H₄O²⁺ exist?
Why do I get two different answers for this counting problem?
What killed these X2 caps?
How can I fix/modify my tub/shower combo so the water comes out of the showerhead?
Alternative to sending password over mail?
Why is consensus so controversial in Britain?
Autoit Date reformat
Java string to date conversionGetting Python and AutoIT to work together using win32com: what's up with those window handles?GUICtrlCreateDate set date in autoitConvert date string (EST) to Java Date (UTC)Convert an integer to a 2 byte Hex value in PythonCall functions in AutoIt DLL using Python ctypesAssign contents of Excel cell to string variable in AutoITHow do I convert one date format into another date format in Java?How do you get ONE variable to equal multiple lines of a .txt file in AutoIt?from “21 marzo 2017” to Unix timestamp
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a variable that holds a string representing a date.
$d = "March 17,2019"
Actually, my code doesn't set d's value like that, but for arguments sake, lets assume that d holds a string date in the format shown.
Is there an easy way to change that d$ string to be in the following format instead: mm/dd/yy format?
Thanks
autoit data-conversion
add a comment |
I have a variable that holds a string representing a date.
$d = "March 17,2019"
Actually, my code doesn't set d's value like that, but for arguments sake, lets assume that d holds a string date in the format shown.
Is there an easy way to change that d$ string to be in the following format instead: mm/dd/yy format?
Thanks
autoit data-conversion
add a comment |
I have a variable that holds a string representing a date.
$d = "March 17,2019"
Actually, my code doesn't set d's value like that, but for arguments sake, lets assume that d holds a string date in the format shown.
Is there an easy way to change that d$ string to be in the following format instead: mm/dd/yy format?
Thanks
autoit data-conversion
I have a variable that holds a string representing a date.
$d = "March 17,2019"
Actually, my code doesn't set d's value like that, but for arguments sake, lets assume that d holds a string date in the format shown.
Is there an easy way to change that d$ string to be in the following format instead: mm/dd/yy format?
Thanks
autoit data-conversion
autoit data-conversion
edited Mar 7 at 21:48
Allied Stack
asked Mar 7 at 21:35
Allied StackAllied Stack
236
236
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
One more Basic code for your reference
$d1 = "March 17,2019"
$year=StringRight($d1,2) ; if you want like 2019 use StringRight($d1,4)
$rightstr = StringLeft($d1,(StringLen($d1)-5))
$test = StringSplit($rightstr, " ")
$mon = $test[1]
$day = $test[2]
Local $mon1
Local $aMMM[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for $i =0 to 11
if $mon = $aMMM[$i] Then
$mon1 = $i+1
EndIf
Next
$mon1= StringFormat("%02d", $mon1)
$finaldate = $day&"/"&$mon1&"/"&$year
MsgBox(1,"",$finaldate)
add a comment |
$d = "March 17,2019"
$sFormattedDate = _MyDate($d)
If Not @error Then
MsgBox(0, @ScriptName, $sFormattedDate)
EndIf
Func _MyDate($sDate, $iYearLen = 4)
; Get month, day and year from a string (3 = return array of global matches).
$aDate = StringRegExp($sDate, '(w+)s+(d1,2),(d4)', 3)
If UBound($aDate) = 3 Then
; Create an array of months.
$aMonths = StringSplit('January|February|March|April|May|June|July|August|September|October|November|December', '|')
; Match month and return in mm/dd/yy format.
For $i1 = 1 To UBound($aMonths) -1
If $aDate[0] = $aMonths[$i1] Then
If $iYearLen <> 4 Then
$aDate[2] = StringRight($aDate[2], $iYearLen)
EndIf
Return StringFormat('%02d/%02d/%d', $i1, $aDate[1], $aDate[2])
EndIf
Next
EndIf
; Return error 1 if month is not matched.
Return SetError(1, 0, '')
EndFunc
Uses a regular expression to get month, day and year from the date string.
If the month is matched from an array of months, then the array index of
the month is used in StringFormat instead.
This will return 03/17/2019
from March 17,2019
in the example code.
If _MyDate()
fails, @error
is set to the value of 1
.
StringFormat uses %02d/%02d/%d
on each date segment which forces a
zero padding of 2 digits for month and day. If the zero padding is not
needed then remove the 02
between %
and d
.
If you want the year to be only 2 digits, then use 2
as the 2nd
parameter of _MyDate()
.
E.g.
$sFormattedDate = _MyDate($d, 2)
The pattern in StringRegExp uses:
w
to match a word character.d
to match a digit.s
to match a space.
Parentheses are used to get the 3 segments from the date string.
If you want to keep the month as is, and just replace the space and
the comma with a /
.
$d = "March 17,2019"
$sFormattedDate = StringRegExpReplace($d, '[s,]', '/')
MsgBox(0, @ScriptName, $sFormattedDate)
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053174%2fautoit-date-reformat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One more Basic code for your reference
$d1 = "March 17,2019"
$year=StringRight($d1,2) ; if you want like 2019 use StringRight($d1,4)
$rightstr = StringLeft($d1,(StringLen($d1)-5))
$test = StringSplit($rightstr, " ")
$mon = $test[1]
$day = $test[2]
Local $mon1
Local $aMMM[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for $i =0 to 11
if $mon = $aMMM[$i] Then
$mon1 = $i+1
EndIf
Next
$mon1= StringFormat("%02d", $mon1)
$finaldate = $day&"/"&$mon1&"/"&$year
MsgBox(1,"",$finaldate)
add a comment |
One more Basic code for your reference
$d1 = "March 17,2019"
$year=StringRight($d1,2) ; if you want like 2019 use StringRight($d1,4)
$rightstr = StringLeft($d1,(StringLen($d1)-5))
$test = StringSplit($rightstr, " ")
$mon = $test[1]
$day = $test[2]
Local $mon1
Local $aMMM[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for $i =0 to 11
if $mon = $aMMM[$i] Then
$mon1 = $i+1
EndIf
Next
$mon1= StringFormat("%02d", $mon1)
$finaldate = $day&"/"&$mon1&"/"&$year
MsgBox(1,"",$finaldate)
add a comment |
One more Basic code for your reference
$d1 = "March 17,2019"
$year=StringRight($d1,2) ; if you want like 2019 use StringRight($d1,4)
$rightstr = StringLeft($d1,(StringLen($d1)-5))
$test = StringSplit($rightstr, " ")
$mon = $test[1]
$day = $test[2]
Local $mon1
Local $aMMM[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for $i =0 to 11
if $mon = $aMMM[$i] Then
$mon1 = $i+1
EndIf
Next
$mon1= StringFormat("%02d", $mon1)
$finaldate = $day&"/"&$mon1&"/"&$year
MsgBox(1,"",$finaldate)
One more Basic code for your reference
$d1 = "March 17,2019"
$year=StringRight($d1,2) ; if you want like 2019 use StringRight($d1,4)
$rightstr = StringLeft($d1,(StringLen($d1)-5))
$test = StringSplit($rightstr, " ")
$mon = $test[1]
$day = $test[2]
Local $mon1
Local $aMMM[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for $i =0 to 11
if $mon = $aMMM[$i] Then
$mon1 = $i+1
EndIf
Next
$mon1= StringFormat("%02d", $mon1)
$finaldate = $day&"/"&$mon1&"/"&$year
MsgBox(1,"",$finaldate)
answered Mar 8 at 18:45
Jitendra BanshpalJitendra Banshpal
544414
544414
add a comment |
add a comment |
$d = "March 17,2019"
$sFormattedDate = _MyDate($d)
If Not @error Then
MsgBox(0, @ScriptName, $sFormattedDate)
EndIf
Func _MyDate($sDate, $iYearLen = 4)
; Get month, day and year from a string (3 = return array of global matches).
$aDate = StringRegExp($sDate, '(w+)s+(d1,2),(d4)', 3)
If UBound($aDate) = 3 Then
; Create an array of months.
$aMonths = StringSplit('January|February|March|April|May|June|July|August|September|October|November|December', '|')
; Match month and return in mm/dd/yy format.
For $i1 = 1 To UBound($aMonths) -1
If $aDate[0] = $aMonths[$i1] Then
If $iYearLen <> 4 Then
$aDate[2] = StringRight($aDate[2], $iYearLen)
EndIf
Return StringFormat('%02d/%02d/%d', $i1, $aDate[1], $aDate[2])
EndIf
Next
EndIf
; Return error 1 if month is not matched.
Return SetError(1, 0, '')
EndFunc
Uses a regular expression to get month, day and year from the date string.
If the month is matched from an array of months, then the array index of
the month is used in StringFormat instead.
This will return 03/17/2019
from March 17,2019
in the example code.
If _MyDate()
fails, @error
is set to the value of 1
.
StringFormat uses %02d/%02d/%d
on each date segment which forces a
zero padding of 2 digits for month and day. If the zero padding is not
needed then remove the 02
between %
and d
.
If you want the year to be only 2 digits, then use 2
as the 2nd
parameter of _MyDate()
.
E.g.
$sFormattedDate = _MyDate($d, 2)
The pattern in StringRegExp uses:
w
to match a word character.d
to match a digit.s
to match a space.
Parentheses are used to get the 3 segments from the date string.
If you want to keep the month as is, and just replace the space and
the comma with a /
.
$d = "March 17,2019"
$sFormattedDate = StringRegExpReplace($d, '[s,]', '/')
MsgBox(0, @ScriptName, $sFormattedDate)
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
add a comment |
$d = "March 17,2019"
$sFormattedDate = _MyDate($d)
If Not @error Then
MsgBox(0, @ScriptName, $sFormattedDate)
EndIf
Func _MyDate($sDate, $iYearLen = 4)
; Get month, day and year from a string (3 = return array of global matches).
$aDate = StringRegExp($sDate, '(w+)s+(d1,2),(d4)', 3)
If UBound($aDate) = 3 Then
; Create an array of months.
$aMonths = StringSplit('January|February|March|April|May|June|July|August|September|October|November|December', '|')
; Match month and return in mm/dd/yy format.
For $i1 = 1 To UBound($aMonths) -1
If $aDate[0] = $aMonths[$i1] Then
If $iYearLen <> 4 Then
$aDate[2] = StringRight($aDate[2], $iYearLen)
EndIf
Return StringFormat('%02d/%02d/%d', $i1, $aDate[1], $aDate[2])
EndIf
Next
EndIf
; Return error 1 if month is not matched.
Return SetError(1, 0, '')
EndFunc
Uses a regular expression to get month, day and year from the date string.
If the month is matched from an array of months, then the array index of
the month is used in StringFormat instead.
This will return 03/17/2019
from March 17,2019
in the example code.
If _MyDate()
fails, @error
is set to the value of 1
.
StringFormat uses %02d/%02d/%d
on each date segment which forces a
zero padding of 2 digits for month and day. If the zero padding is not
needed then remove the 02
between %
and d
.
If you want the year to be only 2 digits, then use 2
as the 2nd
parameter of _MyDate()
.
E.g.
$sFormattedDate = _MyDate($d, 2)
The pattern in StringRegExp uses:
w
to match a word character.d
to match a digit.s
to match a space.
Parentheses are used to get the 3 segments from the date string.
If you want to keep the month as is, and just replace the space and
the comma with a /
.
$d = "March 17,2019"
$sFormattedDate = StringRegExpReplace($d, '[s,]', '/')
MsgBox(0, @ScriptName, $sFormattedDate)
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
add a comment |
$d = "March 17,2019"
$sFormattedDate = _MyDate($d)
If Not @error Then
MsgBox(0, @ScriptName, $sFormattedDate)
EndIf
Func _MyDate($sDate, $iYearLen = 4)
; Get month, day and year from a string (3 = return array of global matches).
$aDate = StringRegExp($sDate, '(w+)s+(d1,2),(d4)', 3)
If UBound($aDate) = 3 Then
; Create an array of months.
$aMonths = StringSplit('January|February|March|April|May|June|July|August|September|October|November|December', '|')
; Match month and return in mm/dd/yy format.
For $i1 = 1 To UBound($aMonths) -1
If $aDate[0] = $aMonths[$i1] Then
If $iYearLen <> 4 Then
$aDate[2] = StringRight($aDate[2], $iYearLen)
EndIf
Return StringFormat('%02d/%02d/%d', $i1, $aDate[1], $aDate[2])
EndIf
Next
EndIf
; Return error 1 if month is not matched.
Return SetError(1, 0, '')
EndFunc
Uses a regular expression to get month, day and year from the date string.
If the month is matched from an array of months, then the array index of
the month is used in StringFormat instead.
This will return 03/17/2019
from March 17,2019
in the example code.
If _MyDate()
fails, @error
is set to the value of 1
.
StringFormat uses %02d/%02d/%d
on each date segment which forces a
zero padding of 2 digits for month and day. If the zero padding is not
needed then remove the 02
between %
and d
.
If you want the year to be only 2 digits, then use 2
as the 2nd
parameter of _MyDate()
.
E.g.
$sFormattedDate = _MyDate($d, 2)
The pattern in StringRegExp uses:
w
to match a word character.d
to match a digit.s
to match a space.
Parentheses are used to get the 3 segments from the date string.
If you want to keep the month as is, and just replace the space and
the comma with a /
.
$d = "March 17,2019"
$sFormattedDate = StringRegExpReplace($d, '[s,]', '/')
MsgBox(0, @ScriptName, $sFormattedDate)
$d = "March 17,2019"
$sFormattedDate = _MyDate($d)
If Not @error Then
MsgBox(0, @ScriptName, $sFormattedDate)
EndIf
Func _MyDate($sDate, $iYearLen = 4)
; Get month, day and year from a string (3 = return array of global matches).
$aDate = StringRegExp($sDate, '(w+)s+(d1,2),(d4)', 3)
If UBound($aDate) = 3 Then
; Create an array of months.
$aMonths = StringSplit('January|February|March|April|May|June|July|August|September|October|November|December', '|')
; Match month and return in mm/dd/yy format.
For $i1 = 1 To UBound($aMonths) -1
If $aDate[0] = $aMonths[$i1] Then
If $iYearLen <> 4 Then
$aDate[2] = StringRight($aDate[2], $iYearLen)
EndIf
Return StringFormat('%02d/%02d/%d', $i1, $aDate[1], $aDate[2])
EndIf
Next
EndIf
; Return error 1 if month is not matched.
Return SetError(1, 0, '')
EndFunc
Uses a regular expression to get month, day and year from the date string.
If the month is matched from an array of months, then the array index of
the month is used in StringFormat instead.
This will return 03/17/2019
from March 17,2019
in the example code.
If _MyDate()
fails, @error
is set to the value of 1
.
StringFormat uses %02d/%02d/%d
on each date segment which forces a
zero padding of 2 digits for month and day. If the zero padding is not
needed then remove the 02
between %
and d
.
If you want the year to be only 2 digits, then use 2
as the 2nd
parameter of _MyDate()
.
E.g.
$sFormattedDate = _MyDate($d, 2)
The pattern in StringRegExp uses:
w
to match a word character.d
to match a digit.s
to match a space.
Parentheses are used to get the 3 segments from the date string.
If you want to keep the month as is, and just replace the space and
the comma with a /
.
$d = "March 17,2019"
$sFormattedDate = StringRegExpReplace($d, '[s,]', '/')
MsgBox(0, @ScriptName, $sFormattedDate)
edited Mar 9 at 2:35
answered Mar 7 at 23:57
michael_heathmichael_heath
3,0772719
3,0772719
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
add a comment |
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
Very Nice answer @michale_heath
– Jitendra Banshpal
Mar 8 at 18:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053174%2fautoit-date-reformat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown