Jump to content
Sign in to follow this  
frew

How to change date format when using _DateTimeFormat?

Recommended Posts

frew
Posted (edited)

Hello,

My goal here is to press a key combination to send the current date in this format, for example:

(the hotkey is not the problem...what I want is for this particular format to show up)

_5-27-18

At the moment I have a hotkey set to run this script that I found in the help file:

_DateTimeFormat

#include <Date.au3>
#include <MsgBoxConstants.au3>

; Show current date/time in the pc's format
;MsgBox($MB_SYSTEMMODAL, "Pc Long format", _DateTimeFormat(_NowCalc(), 1))     ;(not using this line of the script)
MsgBox($MB_SYSTEMMODAL, "Pc Short format", _DateTimeFormat(_NowCalc(), 2))

The result that shows up is

5/27/2018

What adjustments can I make to have this formatting show up instead:

_5-27-18

Thanks for any ideas.

Edit:

And how can I get this date and formatting to be in the Clipboard for easy pasting into names of Firefox articles I save.

That's why I'm interested in this. I like to save articles, and I put the date at the end of the article name,

but Windows does not allow slashes in the filenames.

EndEdit

 

Edit_2

I don't see this particular formatting option in the dropdown menu on this Windows 10

"change date and time formats" settings.

EndEdit_2

 

 

 

Edited by frew

Share this post


Link to post
Share on other sites
Chimp

... if the problem is only the "/" char because is not allowed in filenames, then you could change it with a minus for example using the StringReplace() function like in this way:

StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-")

... and put it in the clipboar using the ClipPut() function in this way
 

ClipPut(StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-"))

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
frew
Posted (edited)

Thanks for the idea.

So now I have this script in order to get the exact results I want.
I'm a little embarrassed to show it, because I just keep modifying it until it
gets the results I want...so here it is:

 

;when I click Ctrl+S to save a webpage in Firefox, when the dialog box comes up,
;I then press my hotkey I have set up, in this case I use Alt+1, and that runs
;this script to get the result that I want, in this case _5-27-18

#include <Date.au3>;edit: that #include <Date.au3> only showed up as #include until this edit
Sleep(100)

;note that Ctrl+S brings up the dialog box with the name field webpage name fully selected

;gets the mouse not over any other files in the dialog box,
;otherwise for some reason the other files names may show up in the name field
MouseMove(470, 920, 0)
Sleep(500)

;for some reason Send("{End}") does not affect the name field unless I
;move away from it with Tab then back to it,
;and for some reason I have to Tab 3, then Shift+Tab 2
Send("{TAB 3}")
Sleep(500)
Send("+{TAB 2}")
Sleep(500)

;after doing all that Tabbing, now End will go to the end of the name field
Send("{End}")
Sleep(500)

;gets rid of the .html at the end of the filename for now
Send("{BS 5}")
Sleep(500)

Send("_", 1);1 flag to send the underscore "Raw"
Sleep(500)

;this line is Chimps idea, at AutoIt forum, works nicely to replace slashes with dashes
;and puts the time now into the clipboard
ClipPut(StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-"))

;then I modify the formatting "manually" a little further to get the exact result I want
Sleep(500)
Send("^v")
Sleep(500)
Send("{Left 2}")
Sleep(500)
Send("{BS 2}")
Sleep(500)

;then I click Enter to save the file with the date at the end formatted how I like it




I know it's not the best or most elegant way, but it works.

Thanks for any other ideas too.

Edited by frew

Share this post


Link to post
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
Sign in to follow this  

×