Solved Extracting day of week

February 23, 2014 at 11:53:22
Specs: Windows 7, Intel(R) Core(TM) i3 / 3.20 GHz / 8 GB Ram
So I have searched the hole freaking internet and it seems like it forgot how to extract the day of week in a command line.

All I need is to get the day of the week(any format works really).

Any help would be appreciated.


See More: Extracting day of week

Report •

✔ Best Answer
February 25, 2014 at 13:13:57
Hi M2: debug works in win7 32-bit, but not 64-bit, is my uinderstanding. This version eliminates the two temp-files:
@goto :10
f100,108,b4,2a,cd,21,b4,4c,cd,21
g
q
:10
@echo off & setlocal
debug < %0.bat>nul
:: if %errorlevel% equ 0 set day=...
echo %errorlevel%

message edited by nbrane



#1
February 23, 2014 at 19:27:49
If your date format is like this: Sun xxxx then just extract the first 3 chars:

set dofw=%date:~0,3%
echo day of week is %dofw%

If your date format is otherwise, then you'll need to post your system's format to get an effective solution.


Report •

#2
February 24, 2014 at 05:25:11
I can't set my date format to show the day of week? Only d(d). MMMM yyyy on long and on short there neither is no dddd? Do I have to switch to another language?


Report •

#3
February 24, 2014 at 07:27:03
Powershell's an option. Amusingly it'll run base64 encoded strings, so you have no idea if this prints out the current day of week or if it formats your hard drive.
powershell -EncodedCommand IgB7ADAAOgBkAGQAZAB9ACIAIAAtAGYAIABbAEQAYQB0AGUAVABpAG0AZQBdADoAOgBUAG8AZABhAHkA

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
February 24, 2014 at 09:03:10
Wait a sec, if this could potentially format the hard drive, could hackers not use that if they just had access to running a single powershell?

"{0:ddd}" -f [DateTime]::Today
Right?

message edited by SilasPc


Report •

#5
February 24, 2014 at 10:59:36
SilasPc: could hackers not use that if they just had access to running a single powershell?
Well, there are rules involved, thanks to UAC. In theory, the best someone could do would be to screw up / delete the current user. The one that has all of the documents you care about. In practice, you could throw something in one of the user's auto-run sections, and have that request elevation. It'd be a part of the request for elevation people have when they install poorly designed programs that demand to be run when the user logs in, and demand elevation. (Java updater, I'm looking at you.) If the user does elevate, BAM, formatted C:.

My general point is that you shouldn't run anything without first knowing that it does. A base64 chunk means I could be obscuring my code. In my case it's not intentional; I just didn't want to work out which delimiters and their locations I would need to get the line passed correctly to Powershell. It's probably the double quotes, but I digress.

SilasPc: "{0:ddd}" -f [DateTime]::Today
Right?

Yep. Take today, and pull out the abbreviated day of week. A fourth 'd' will give you the full day of week name.

EDIT: You'll still need to do something from the batch side to capture its output. Probably by wrapping the entire thing in a FOR /F loop.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#6
February 25, 2014 at 01:04:00
There's a simple way using DEBUG but I think it got left out of win7.


::====== script starts here ===============
:: creates DAY.com and sets today
:: silas.bat 2014-02-24 18:16:42.36
@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo Q
debug < d.d
DAY

if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo today %day%

del DAY.COM & del d.d
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#7
February 25, 2014 at 13:13:57
✔ Best Answer
Hi M2: debug works in win7 32-bit, but not 64-bit, is my uinderstanding. This version eliminates the two temp-files:
@goto :10
f100,108,b4,2a,cd,21,b4,4c,cd,21
g
q
:10
@echo off & setlocal
debug < %0.bat>nul
:: if %errorlevel% equ 0 set day=...
echo %errorlevel%

message edited by nbrane


Report •

Ask Question