01-30-2012 02:18 PM
I'm creating a file with the date it was first created and I'm adding to it more info everytime my vi is called. I want to stop adding if the file is older than 7 days, any idea how to approach this?
I tried using time stamps but I couldnt get to the index of the day.
Thanks.
01-30-2012 03:03 PM
Subtract the current date/time from the file date/time timestamp. When the value is greater than 7x86,400 (7 days x seconds in a day), then 7 days have passed.
01-30-2012 03:05 PM
I came up with two ways, I attached one to turn a boolean on every Monday, which in turn can obviously be used to start a new measurement file. However, in the expressVI write to measurement file you can specify to save to a series of files. There are probably other ways to do it as well using the by scanning a time date string, but these seem to be the two easiest that come to mind.
-Franklin
01-30-2012 03:53 PM
01-30-2012 03:58 PM
Here are a couple of methods you could use. For similar purposes I usually normalize all times to start at midnight, so I have a simple subVI that gives me the timestamp for midnight of the date in a timestamp. Then you can subtract timestamps and convert seconds to days easily. The snippet shows two methods: Find difference between midnight of two entered timestamps, or simply find the difference in days between two timestamps (this method likely starts new files in the middle of the day). I use the former and if it is greater than six days, time for a new file. (I usually like to start new files daily, typically at midnight).
01-31-2012 09:08 AM
thanks guys, would you be so kind and downconvert the VI and the snippet for me?
thanks,
peter
01-31-2012 01:21 PM
what if you were to start saving the data each saturday at midnight and finish next saturday at midnight?
01-31-2012 01:31 PM - edited 01-31-2012 01:32 PM
@spaaw wrote:
what if you were to start saving the data each saturday at midnight and finish next saturday at midnight?
Easy as pie!
If its Saturday see
if a file exists with todays date in the filename.
write to it
else create it write to it,
Else (Not Saturday) write latest file
01-31-2012 02:04 PM - edited 01-31-2012 02:12 PM
thanks for the quick replay!
here is a more detailed description on what I want to achieve:
I will be creating an excel spreadsheet with data. There will be 1 excel spreadsheet for each week of the month (starting Sat at Midnight and finishing saving data after 168 hours on the next Sat at Midnight). Data will be added to the spreadsheet throughout Sat - Sat. Now, lets assume the first spreadsheet file created will happen on Thursday.. how can I tell it to stop saving on Saturday at Midnight and start saving new data to a new, fresh excel spreadsheet?
so basically:
VERY FIRST Data write to the spreadsheet =true?
Create spreadsheet at current time.
ADDITIONAL Data write to the spreadsheet:
See if that file is within SAT-SAT
If it is, keep adding data to it.
If its not, create new spreadsheet.
My issue is that I do not have a constant here. The first spreadsheet could be created on any day of the week.. If i had a constant i could just see if a week has passed from its creation..
I will be working on it and I will keep you updated if i find a solution.
Any help is appreciated!
thanks
01-31-2012 02:16 PM
@spaaw wrote:
thanks for the quick replay!
here is a more detailed description on what I want to achieve:
My issue is that I do not have a constant here. The first spreadsheet could be created on any day of the week.. If i had a constant i could just see if a week has passed from its creation..
I will be working on it and I will keep you updated if i find a solution.
Any help is appreciated!
thanks
so. expanding on the example from previous.
if it is not saturday use the latest file if it was created this month or create a new one