Day of week batch file


















Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. It automatticly checks which day it is. Here is an example bat file that will do this sort of thing I am sure you can think of other ways to use this sample code.

For instance anytime you need an "in" list. I ran across this online. Tested, and it works. Returns the day as an integer, which you can still work with. If you don't mind mixing your batch files with some VBScript, here's a solution that should work on all locales.

I don't have the batch fu to answer the question as asked, but, assuming this is a Windows batch file, consider executing the script using the task scheduler, which will let you set the kind of schedule you're asking for.

Here is a batch file that extracts day-of-week, day, month and year in an almost locale-neutral way. So in English, it will return Thu for Thursday, but in Dutch that will be do for donderdag. Expanding on this based on suggestions in this thread , we can set a dayofweek variable as follows:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Asked 12 years, 7 months ago. This really works, now you just have to fumble the DOW out of the outputstring and you're done To avoid having to redirect to a text file, there is a variation of the FOR which takes a command string. Here it is:. Remember to use double percent signs if you put this command in a dos script. In my example, I checked for the common date delimiter character of forward slash or dash. How about this one for Windows , much more elegant.

Also will work anywhere powershell is installed. I am in the US. All with short date setting without ddd or dddd day of week. This returns the day on all 4 Windows versions I have tested on. And only the day. Thu, which tells me this code does use the short date format. But what also may be happening is that if the short date does not contain the day of week, it may look to the long date format which on all 4 machines I tested on, have dddd in the format.

The solution posted by Atntoni Gual works on plain batch but we must assign some variables before doing the calculation. Got same problem with WR2 server which worked accordingly before. Probably someone changed region settings for Short date. Did some testing with region settings for short date and now its working again:.

Ok, found an answer I couldn't find a way using plain BAT files, but if you have access to powershell EDIT: for potential people stumbling on this This is nasty and ugly, and shouldn't be done, and other answers to this question are better, if they apply to you. If you NEED to get this done quickly and dirty within a batch file you already have, this could work for you, though.

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Learn more. Finding day of week in batch file? Windows Server Ask Question. Asked 12 years, 1 month ago. Active 11 months ago. Viewed k times. Improve this question. Alexander Farber 4 4 gold badges 15 15 silver badges 36 36 bronze badges. Daniel Magliola Daniel Magliola 1, 9 9 gold badges 19 19 silver badges 32 32 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. RobW RobW 2, 1 1 gold badge 15 15 silver badges 22 22 bronze badges.

How to save that into a variable? Danny Beckett Danny Beckett 2 2 silver badges 14 14 bronze badges. John Gardeniers John Gardeniers 27k 12 12 gold badges 52 52 silver badges bronze badges. I've used similar to this in a Batch file that ran daily to identify the day and only run a line of code on a specific day. It allows you specify the days you want it to run and what time: You could also use VBScript: wscript.

Glorfindel 1, 3 3 gold badges 14 14 silver badges 22 22 bronze badges. John T John T 1, 1 1 gold badge 15 15 silver badges 19 19 bronze badges. I basically have A batch file that does a bunch of stuff backups , and some of that stuff HUGE folders that are not that important and don't change often , I want to only do it once a week to save hours of daily time.

The new method is also shorten, but no simpler! Aacini's answer has got two weak points although it suffices for many applications, and it is a great approach after all! The following is a revised version of Aacini's batch script described within explanatory remarks :.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to get the day of year in a batch file Ask Question. Asked 6 years, 5 months ago. Active 1 year, 5 months ago. Viewed 6k times. How can I get the day of year from the current date in a Windows batch file? Are you talking about the Julian date?

If so, stackoverflow. That answer works for me. Thanks a lot. Ghost — geek



0コメント

  • 1000 / 1000