Jump to content

Recommended Posts

Posted (edited)

These two simple Functions convert from a UK formated date to a US formated date or vice versa.

#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sUKDate = @MDAY & '/' & @MON & '/' & @YEAR
    Local $sUSDate = @MON & '/' & @MDAY & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC

    MsgBox($MB_SYSTEMMODAL, '', 'Was ' & $sUKDate & ' & now it''s ' & _UKToUSDate($sUKDate) & ' in the US Format.')
    MsgBox($MB_SYSTEMMODAL, '', 'Was ' & $sUSDate & ' & now it''s ' & _USToUKDate($sUSDate) & ' in the UK Format.')
EndFunc   ;==>Example

Func _UKToUSDate($sDate) ; DD/MM/YYYY >> MM/DD/YYYY
    Return StringRegExpReplace($sDate, '^(\d{2})\D?(\d{2})\D?(\d{4})([\d\s:]*)$', '\2/\1/\3\4')
EndFunc   ;==>_UKToUSDate

Func _USToUKDate($sDate) ; MM/DD/YYYY >> DD/MM/YYYY
    Return StringRegExpReplace($sDate, '^(\d{2})\D?(\d{2})\D?(\d{4})([\d\s:]*)$', '\2/\1/\3\4')
EndFunc   ;==>_USToUKDate
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Ha Ha! Maybe I should have posted tomorrow! :)

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 2 years later...
Posted

I've updated the regular expression pattern. It will now accept dates without delimiters.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 10 months later...
Posted

Updated the function to accept the optional hh:mm:ss of a date string.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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