Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Powershell work with files created with previous Date after midnight..

Powershell work with files created with previous Date after midnight..

Powershell work with files created with previous Date after midnight..

I'm after a bit of help please in regards to the best way to handle a issue i have with a small "app" Ive inherited...

this is a small PowerShell GUI/code which controls a handover document for a 3 shift rota system (i.e days, eves, nights). Each day we create 3 text files into a dated subfolder which are then edited throughout each shift via the "app" and then reviewed/updated etc and archived the next morning where the cycle starts again.

my "problem" is with the night shift handover in that the file /folder is created for "today" (i.e. 20200619) at the start of each day when the day shift starts (07:00) which is fine but the night shift itself then starts at 23:00 and goes on until 07:00 the next day. When they start they open the current days file but once it hits midnight, it then tries to open the folder/file for the following date ie. the one dated 20200620 which doesnt exist.

Weve tried pre-allocating the day ahead but this then means that we may have part of the handover saved in the 20200619 file and part after midnight in the 20200620 file...weve tried checking/comparing the time
too and whilstt this made it a bit better when they keep the app active, if the apps restarted after midnight all the dates shifted again and we were back to square 1...

Current thinking is to now save the date into another external file when the logs are created and read this date each time to retrieve the right file but wonder if anyone can suggest a possible alternate soltution please.

Apologies but I'm unable to publish any of the code due to "security" restrictions in place (and understand that this may restrict any help or responses I receive but all will be appreciated...)


RE: Powershell work with files created with previous Date after midnight..

your best option would be to change your application to work based on start of shift period - would require some kind of configuration and logic but would work.
shift 1 - from 7 to 15 - folder name = current date + 1 (shift 1) (20200619_1)
shift 2 - from 15 to 23 - folder name = current date + 2 (shift 2) (20200619_2)

shift 3 would require logic - if current time is < 7 use previous day else use current day
shift 3 - from 23 to 07 (+1) - folder name = date from logic + 3 (shift 3) (20200619_3)


Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close