How Add a time if, and use string to save a file

I need to save a .csv file, inserting the saving time (HH) in the name, but…
for technical reasons, the first RUN of the day (h: 8: 00) is sometimes completed late.

for this reason, I have to anticipate the draw, starting at 7:30 in the morning, so that by 8:00 - 08:15 it will be ready.
What is needed:

  • if the run is completed before 8:00, I have to add 1h to the file name.
  • if the run is completed after 8:00, I can use the current time.

I don’t know how to add a string that calculates the correct time.

ex: if before 8:00 am = “namefile_now.tostring (” ddMMyyyy_HH ") + add 1h .csv

ex: if after 08:00 “namefile_now.tostring (” ddMMyyyy_HH ").csv

Can anyone kindly help me with this?
Thanks a lot!


Check as below for your reference

Hope this may help you


like this~?

fileName = DateTime.Now.ToString(“ddMMyyyy_HH”)
if DateTime.Now.Hour < 8
fileName = DateTime.Now.AddHours(1).Tostring(“ddMMyyyy_HH”)


WoW! Super fast!
With the same solution.
I did a test and it works correctly.
I select the first chronological solution as a solution, it seems to me the right thing.
Thank you very much, very kind, both of you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.