Jump to content
Sign in to follow this  
tommytx

Time Date formatting question...

Recommended Posts

tommytx

Back in the good old days of PHP and even now.. you could set the date and time up any way you liked by just adding any separator you liked and positioning the variables in any sort of way...

But I cannot find the same here in autoit unless I just don't understand what I am reading..

For example my date time comes out:

2/23/2013 and time is ok like 13:51:34 for 24 hour time...

but here is what i need:

2013-23-02 13:51:34 but to get this I am doing a lot of jacking around... am I making this too hard?

$mytime = _NowDate() & " " & _NowTime(5)

2/23/2013 13:51:34 Need 2013-23-02 13:51:34

Just changing the : to a dash and changing the / to a dash..
But isn't there a format that gives the above without all the work?

$fname = "data\" & $key_phrase & "-" & $mytime & ".htm"
$fname = StringRegExpReplace($fname, "/", "-")
$fname = StringRegExpReplace($fname, " ", "-")
$fname = StringRegExpReplace($fname, ":", "-")
Edited by tommytx

Share this post


Link to post
Share on other sites
Melba23

tommytx,

Try Malkey's _Date_Time_Convert UDF - it converts to and from any format you want. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
water

Maybe _DateTimeFormat is what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

tommytx,

It appears that you are trying to construct a date/time stamped file name. You might try something like one of these:

#include <date.au3>
local $file_name = 'My_Base_Name_' & @year & '-' & @mon & '-' & @mday & '_' & @hour & '-' & @min & '-' & @SEC
ConsoleWrite($file_name & @LF)
$file_name = 'My_Base_Name_' & stringregexpreplace(_now(),'[/ :]','-')
ConsoleWrite($file_name & @LF)

kylomas

edit: _tempfile() might suit your need if you do not need to control the formatting

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
tommytx

Kylomas:

Thanks that worked perfect... also thanks for the suggestions from all the others... sorry for the long acknowledgement, as it appears I did not get on the auto notify list... so did not get notified of all the fantastic activity on this thread.... sure not like Sales Force.. almost no one ever answers.....

Share this post


Link to post
Share on other sites
kylomas

If you are writing log type records _filewritelog() is a UDF that makes this easy. It also allows for writing to either the beginning or end of the log file.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
RichardL

If you use @year...@sec is it possible to get incorrect values by reading across a whole minute change? Better to read the whole date-time from the OS in one go, then reformat.

Share this post


Link to post
Share on other sites
kylomas

RichardL,

If you use @year...@sec is it possible to get incorrect values by reading across a whole minute change?

Yes, for timing or duration use one of the timer functions or UDF's. This is a simple date/time stamp on a log record or file name.

Better to read the whole date-time from the OS in one go, then reformat.

Depends on appplication...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

  • Similar Content

    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • Rskm
      By Rskm
      Hi, for a script of mine, I wish to keep a time frame on till how the program will work.. basically, I want the program to read the date and if the read date < 'a particular date', the program continues, else it exit. I don't want to read the time from the computer as the program can be fooled by resetting the pc time. is there a way to read time from internet - so that the user cannot fool the program by date reset? thanks
    • Siryx
      By Siryx
      So what i need is a function that I pass a starting date into and it counts up to the current date. Example:
      2009-05-30
      2009-05-31
      2009-06-01
      ...
      2018-06-18
      How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale.
      €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for  
    • nacerbaaziz
      By nacerbaaziz

      Hello
      I have a question please
      How to show Islamic date in Autoit
      I mean
      for example
      Ramadan month
      And moharam month ... etc
      I hope my question is clear for you
      Thanks in advance
×