Jump to content

Format date string


Recommended Posts

Hi everyone

I have a string that contains a date. The date is formated "yyyy/MM/dd".

Is there any simple way to change the format to "d MMM -YY"

Ifound something like _GUICtrlDTP_SetFormat() But that just seems to work on actual controls witch this isn't!

Would be thankful over some help!

Link to comment
Share on other sites

Link to comment
Share on other sites

#include <Date.au3>

; "yyyy/mm/dd" to "d mmm-yy"format
$sDate = "2009/12/01"
$aDate = StringSplit($sDate, "/")
$sDate_New = Number($aDate[3]) & " " & _DateToMonth($aDate[2], 1) & "-" & StringRight($aDate[1], 2)

MsgBox(0, "Date Format", '"yyyy/mm/dd" = ' & $sDate & @CRLF & '"d mmm-yy" = ' & $sDate_New & @CRLF & "Reg Exp Rep = " & _
        Execute(StringRegExpReplace($sDate, "(.{2})(.{2})/(.{2})/(.{2})", _
        'number("\4") & " " & _DateToMonth("\3", 1) & "-" & "\2"')))

Link to comment
Share on other sites

Try this:

#include <DateTimeConstants.au3> ;For the date control
$dateinput=GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY, 670, 67, 155, 20) ;Create the control- for reference
$DTM_SETFORMAT_ = 0x1032 ;Will start to change the style
$style = "d MMM yy"
Edited by Crash

JPGRARMouse Lock | My website | Thanks so much for your help! ❤️

Link to comment
Share on other sites

Try this:

#include <DateTimeConstants.au3> ;For the date control
$dateinput=GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY, 670, 67, 155, 20) ;Create the control- for reference
$DTM_SETFORMAT_ = 0x1032 ;Will start to change the style
$style = "d MMM yy"

Here is another example of Crash's method.

Local $Date = "1953/04/05 14:30:11.6"

MsgBox(0, "Date Format", 'Date = ' & $Date & @CRLF & _
    '"d MMM-yy" ' & @tab & " = " & _DateFormat($Date, "d MMM-yy") & @CRLF & _
    '"dddd, d MMMM, yyyy" = ' & _DateFormat($Date, "dddd, d MMMM, yyyy") & @CRLF & _
    '"dd/MM/yyyy" ' & @tab & " = " & _DateFormat($Date, "dd/MM/yyyy") & @CRLF & _
    '"HH-mm-ss or h:mm tt"" = ' & _DateFormat($Date, "HH-mm-ss or h:mm tt"))


Func _DateFormat($Date, $style)
    Local $hGui = GUICreate("My GUI get date", 200, 200, 800, 200)
    Local $idDate = GUICtrlCreateDate($Date, 10, 10, 185, 20)
    GUICtrlSendMsg($idDate, 0x1032, 0, $style)
    Local $sReturn = GUICtrlRead($idDate)
    GUIDelete($hGui)
    Return $sReturn
EndFunc ;==>_DateFormat

Edit: Added time element to MsgBox display for completeness.

Edit2: Added GuiDelete to function as per KaFu's suggestion Post #6.

Edited by Malkey
Link to comment
Share on other sites

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...