LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

automatically creating data filename out of date and time information

I read somewhere (in a book, here ?) about a programmer who never keyed in a data filename to save his data file. He just used the system date and time to create his filename. For example: now would be 20028141032.dat (2002, August 14, 10:32 am)

I am looking to do something similar. I do want to add a spot of text after the date and time and save it as *.xls.

This way when you have a long list of data files, if you sort by name, they are sequentially in order.

Thanks for any help.

Terry
0 Kudos
Message 1 of 19
(5,912 Views)
"Format Date/Time String" on the Time and dialog palette.

Spec the format the way you want and then concantenate with your specific string before feeding the file I/O VI's.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 19
(5,911 Views)
Hi Terry,

You can use "Seconds to Date/Time" Funtion along with "File Dialog" Function to accomplish your task. You Unbundle the cluster from the "Seconds to Date/Time" with Year, Month, Day, Hour and Minute Information Convert and Append into One String. You Can add Pre or Post text to this String. Wire this to File Dialog Box and it will Pop up the Window With File Name in it as Default. Also the extemsion of the file name can be specified here. The User has Option to change this or accept this default name.

I have attached an Example Vi to Illustrate this(LV6.1) Take a Look. To Use this Just Wire the Path Information to your Saving Functional VI. Also the Vi Checks if File Exists or Dialog Box is Cancelled. And You may Build Functionality for the
se if you need them.

Good Luck.

Mache
Good Luck!

Mache
Message 3 of 19
(5,911 Views)
Hi,
try Get Date/Time In Seconds -> Number To Decimal String -> Concatenate
Strings (add any strings you need like .xls etc) -> String To Path.

You can also use Get Date/Time String if you want a more readable time
than just seconds. I find it easier to sort the time stamps Windows puts
on the files in the explorer, that way you can use a meaningful name for
the files.

Regards,
Dave R.
0 Kudos
Message 4 of 19
(5,677 Views)
THANK YOU!!! This is exactly what I was looking for.
0 Kudos
Message 5 of 19
(5,911 Views)
Hi, I am using the sample you sent me. I need to make a modification that I am struggling with. I don't want the file open box to show up, I just want the file to be saved automatically. I have tried taking out the "File" box, but can't seem to get it to work.

Thanks Terry
0 Kudos
Message 6 of 19
(5,911 Views)
Terry,

The method above uses file dialog, which you don't want. As indicated elsewhere, you need to use the "Format Date Time String" function. In the "Format String" you can add whatever text you want to the filename, and the filename will be based on your format.

I have used this method for the past 5 years to automatically generate filenames. The one thing you have to be careful of is overwriting files. If you don't include either minutes or seconds in your filename, it is possible to overwrite files. Now, if, for example, you are SURE you won't write more than one file in the same minute (that means you won't write files more often than every TWO minutes!!!) you don't need seconds. If you do write a file sooner, it's probably
because of an error, and you need to be careful not to overwrite the original (and probably good) file.

Experiment with the format string and format date time function to see what you can accomplish. As indicated, all you then have to do is convert it to a path.
Message 7 of 19
(5,911 Views)
Hi Terry,

The Original Vi I sent you showed the dialog box so user may change the name he/she wishes or accepts default, besides giving visual feedback of "Saving"

I have Modified the Original so that you can choose to show Dialog or go "Silent". With Silent you have to Specify the Path "C:\" or Whatever. Take a Look!!

Another way is to use the "Format..." Function as mentioned by others. The fuction will return string in Date time as wanted but it will be like 8/23/2002. Now you will have to removes the "Slashes" because Filenames cannot have slashes.

Either way is effective. Your Choice.

Regards,
Good Luck!

Mache
0 Kudos
Message 8 of 19
(5,911 Views)
Oh!! By the Way Once you have the File Path in the "Silent" Case you will have to Wire "NEw File" and "Write File" Funtions to save your data. I hope you can take it from here.

Mache
Good Luck!

Mache
0 Kudos
Message 9 of 19
(5,911 Views)
The statement "The fuction will return string in Date time as wanted but it will be like 8/23/2002" is incorrect.

The format date/time string function will only insert those characters you wish.

For example, the format string "%m%d%H will return "082316" for August 23, 16:xx hours. If you wanted to add anything else, for example, "File" to the name, you just add exactly that to the format string. Thus, a format string of "File%m%d%H" will return "File082316" (I know, because I just did it, using a very old file format I made in LabVIEW 5.1 running on LabVIEW 6.0.2 just now!).

I have included a screen shot of this method, so you can see it's simplicity.

-Mike
Message 10 of 19
(5,911 Views)