Jump to content

How to get current Datetime in a specific format? - (Moved)


KDoc
 Share

Recommended Posts

Hi,

Is there any function or script in Autoit which will return the current date time in a specific format that is indexable as follows:

For example, for today's date of 02/16/2022 time 01:30:05 pm it will return 20220216133005? 

Thanks

Kris

Link to comment
Share on other sites

Hi @KDoc,

I don't know a out of the box variant, but you requirement should be matched by that simple function:

#include-once
#include <Date.au3>

ConsoleWrite(_GetCurrentDateTimeAs_YYYYMMDDHHMMSS() & @CRLF)

Func _GetCurrentDateTimeAs_YYYYMMDDHHMMSS()
    Local Const $iStripAllWhitespaces = 8
    Local $sDateTime = _NowCalc()

    $sDateTime = StringReplace($sDateTime, '/', '')
    $sDateTime = StringReplace($sDateTime, ':', '')

    Return StringStripWS($sDateTime, $iStripAllWhitespaces)
EndFunc

Is that enough or do you need it more dynamically?

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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...