Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Recent Posts

Pages: [1] 2 3 ... 10
Batch+Powershell version. The Batch uses USEBACKQ to call Powershell directly to get the current day of the week directly, then just has a GOTO ladder based on that. Of note is that (get-date).DayofWeek is locale specific; it will give Lundi for Monday of the region is set to French or French-Canadian, for example. So my attempt here uses .Value__ to get the enumeration value instead of having it coalesced via ToString() which considers the current Culture settings. (Now, that said, I think that the actual value will change based on the region settings for the first day of the week; NA uses Sunday as the First Day of the week but I believe places in Europe tend to use Saturday as the first day of the week, which would of course put the numbers "off" from the scripts perspective.

of course setting together various weekdays would be as simple as putting their labels together.

Code: [Select]
@echo off
FOR /F "tokens=* USEBACKQ" %%C in (`powershell ^(get-date^).DayofWeek.Value__`) DO SET weekday=%%C
if %weekday%==0 goto SUNDAY
if %weekday%==1 goto MONDAY
if %weekday%==2 goto TUESDAY
if %weekday%==3 goto WEDNESDAY
if %weekday%==4 goto THURSDAY
if %weekday%==5 goto FRIDAY
if %weekday%==6 goto SATURDAY
echo Do sunday stuff
GOTO ending
echo Do Monday stuff
GOTO ending
echo Do Tuesday stuff
GOTO ending
echo Do wednesday stuff
GOTO ending
echo Do Thursday stuff
GOTO ending
echo Do Friday stuff
GOTO ending
echo Do Saturday stuff
GOTO ending

echo finished.

Code: [Select]

Why do people still want to reinvent things with pure batch instead of a script or code fragment?

Sometimes scripts or executables are restricted due to group policies or domain restrictions. Sometimes the batch will be running in a restricted or stripped environment that doesn't have access to those capabilities,  or has access to some abilities, but not others. Powershell might be unavailable, but WMIC might be, for example.

DOS Functions such as Function 2Ah (Get System Time) which gives back the day of the week in the AL register are rather useless in this context since they cannot be called from command prompt. They can only be called within 16-bit DOS code running under NTVDM, which is only available on 32-bit Windows. So trying to work a assembly executable into a "modern" script for use on modern systems won't work very well.

Nice code examples.

For some time we have been told that there is little need to re invent something in batch that was already provide my Microsoft many years ago.

A look into an old tutorial of Vb Script shoes that data and time functions were included in old libraries. Including a day of week function. My memory is not good enough to remember he details, but I am sure the functions were there shortly after Microsoft introduced DOS. If not is a script, then you could get it with a small bit of assembly code.

I have in my library a book published in 1991 or shortly thereafter that has a list of all the low level things of MS-DOS. One of them will return the day of week.

Why do people still want to reinvent things with pure batch instead of a script or code fragment?  Well, if you get paid by the hours, you can make money doing something that was already done. Until your boss finds out.   :o 
Once again...the Thread that will not die...
Pure batch to get the Date, Day Number and Day Name.

Code: [Select]
@echo off

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
SET "YYYY=%dt:~0,4%"
SET "YY=%dt:~2,2%"
SET "MM=%dt:~4,2%"
SET "DD=%dt:~6,2%"

CALL :DateToDOW %yy% %mm% %dd% dow
CALL :DayName %dow% day
echo day of week is: %dow%
echo Day name is: %day%



:DateToDOW %yy% %mm% %dd% dow
:: By:   Ritchie Lawrence, 2003-04-29. Version 1.1
:: Func: Creates a day of week number from a calendar date, where 1 = Mon
::       and 7 = Sun. For NT4/2000/XP/2003.
:: Args: %1 year component to be converted, 2 or 4 digits (by val)
::       %2 month component to be converted, leading zero ok (by val)
::       %3 day of month to be converted, leading zero ok (by val)
::       %4 var to receive day of week number, 1 to 7 (by ref)
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,dow=153*m+2
set /a dow=dow/5+dd+y*365+y/4-y/100+y/400-2472630,dow%%=7,dow+=1
endlocal&set %4=%dow%&goto :EOF

:DayName %d% day
:: By:   Ritchie Lawrence, 2002-10-04. Version 1.0
:: Func: Returns the day of week from the day number, 1=Monday, 7=Sunday.
::       For NT4/2000/XP/2003.
:: Args: %1 day number to convert to name of day of week, 1 to 7 (by val)
::       %2 var to receive name of day of week (by ref)
for /f "tokens=%1" %%a in ('echo/Monday Tuesday Wednesday Thursday Friday Saturday Sunday') do endlocal&set %2=%%a&goto :EOF
So why are you doin them on your phone ? ?...i'm still confused as *censored*...
Drivers / Re: Dell Lap top Drivers
« Last post by patio on Today at 04:11:12 PM »
Issue was solved a month ago...
Windows XP / Re: unable to update Win XP error 0x80072EFF
« Last post by patio on Today at 03:56:51 PM »
He hasn't been back in 8 Years,,,
Lots of places do surveys just type in best places to do surveys at home, have been a member of AC Nielsen since 1993 back then some surveys were still sent out on paper now it's all computer.
Hardware / Re: Uninstalled Gpu doesnt appear in the device manager
« Last post by Manu-RT on Today at 02:29:25 PM »
Yep i did save the changes

And Yes i took all of the downloads from the official HP website, i even tried with the ones backed up on the pc :/
Computer software / Re: PartedMagic secure (ATA) erase: NULL error
« Last post by Geek-9pm on Today at 02:01:42 PM »
In his case it might be either the HDD or the motherboard. Hard to tell.  Testing the HDD when it is also the system drive is a tough job if the drive is flaky. Easy if the HDD is OK and the issue is only file allocation issues.
If here has another PC at hand, he can try testing the HDD using an external adapter  on the other PC.
Here are two recent  CH links:
Above has links to free HDD test programs.
Below suggest you make sure it is not the driver software.
The fact is, most errors are caused by software (such as drivers) related problems, not by a failing hardware device.
Pages: [1] 2 3 ... 10