Question

Day Script Not Working Anymore

Asked by: simonprr

Hi,

I got the following script from SteveGTR here. I believe since 2006 it hasn't been working out the day name right, like for today it outputs it as Monday. I really need this script to be future proof and work for years to come! Please help!

========================================================
@echo off
cls
setlocal ENABLEDELAYEDEXPANSION

set yyyy=
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
 for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
    set %%x=%%u
    set %%y=%%v
    set %%z=%%w
    set $d1=
    set $tok=))
if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100
set /A dd=1%dd% - 100
set /A mm=1%mm% - 100
set /A dayNum=%dd% + (2 * %mm%) + (3 * (%mm% + 1) / 5) + %yyyy% + (%yyyy% / 4) - (%yyyy% / 100) + (%yyyy% / 400) + 1
set /A dayNum=%dayNum% %% 7

if /i %dd%==01 goto skipdd
if /i %dd%==02 goto skipdd
if /i %dd%==03 goto skipdd
if /i %dd%==04 goto skipdd
if /i %dd%==05 goto skipdd
if /i %dd%==06 goto skipdd
if /i %dd%==07 goto skipdd
if /i %dd%==08 goto skipdd
if /i %dd%==09 goto skipdd
if /i %dd% LSS 10 set dd=0%dd%
:skipdd
if /i %mm%==01 goto skipmm
if /i %mm%==02 goto skipmm
if /i %mm%==03 goto skipmm
if /i %mm%==04 goto skipmm
if /i %mm%==05 goto skipmm
if /i %mm%==06 goto skipmm
if /i %mm%==07 goto skipmm
if /i %mm%==08 goto skipmm
if /i %mm%==09 goto skipmm
if /i %mm% LSS 10 set mm=0%mm%
:skipmm

set day=%dd%
set month=%mm%
set year=%yyyy%
set yy=%yyyy:~2,2%

if %daynum%==1 set daynamefull=Monday& set dayname=Mon
if %daynum%==2 set daynamefull=Tuesday& set dayname=Tue
if %daynum%==3 set daynamefull=Wednesday& set dayname=Wed
if %daynum%==4 set daynamefull=Thursday& set dayname=Thu
if %daynum%==5 set daynamefull=Friday& set dayname=Fri
if %daynum%==6 set daynamefull=Saturday& set dayname=Sat
if %daynum%==0 set daynamefull=Sunday& set dayname=Sun

if %month%==01 set monthname=January& set shortmonthname=Jan
if %month%==02 set monthname=February& set shortmonthname=Feb
if %month%==03 set monthname=March& set shortmonthname=Mar
if %month%==04 set monthname=April& set shortmonthname=Apr
if %month%==05 set monthname=May& set shortmonthname=May
if %month%==06 set monthname=June& set shortmonthname=Jun
if %month%==07 set monthname=July& set shortmonthname=Jul
if %month%==08 set monthname=August& set shortmonthname=Aug
if %month%==09 set monthname=September& set shortmonthname=Sep
if %month%==10 set monthname=October& set shortmonthname=Oct
if %month%==11 set monthname=November& set shortmonthname=Nov
if %month%==12 set monthname=December& set shortmonthname=Dec

echo %daynamefull% %day% %monthname% %year% %time:~0,8%
pause
========================================================

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-02-02 at 09:01:34ID21721151
Tags

dos

,

day

Topic

MS DOS

Participating Experts
4
Points
125
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. double quote (") in delims list !!!
    I want to parse a file and use the double quote (") as a delimiter...but I cannot use the line like : FOR /F "eol=; tokens=1* delims="" because the options are already between double quotes and this is causing a syntax error ! How can I manage that ?? ...
  2. Date and Day Batch File Not Working (Please help SteveGTR)
    i have the following script, which for some werid reason isn't working properly anymore... i believe stevegtr coded this and posted it on various questions on here. firstly, i noticed that the month was coming out as "1" instead of "01" so i added the skip...
  3. Problem with batch file (SteveGTR logic)
    I have a batch file that I have writte that incorporates some code written by SteveGTR to determine the current date and rename a file accordingly. It is now erroring out on all of the batch files I have written, and wanted to see if I could get someone to help me troublesho...
  4. Question for sirbouny & SteveGTR
    Both of you helped me with a vbs and bat file yesterday to modify a java config file. Q_22137181.html I found one snag that I didn't think I would need to worry about but ya know silly me... Some of the machines with that file do not have that line (javaplugin.cache.size=) ...
  5. Robocopy problem with Maximum setlocal recursion.
    When running Robocopy to copy files from one share to another I receive the following output. "Maximum setlocal recursion level reached". This output runs continuously until I manually kill the job. I have tried the following robocopy script straight from DOS ...
  6. CLS for MySQL
    When using the command prompt, a CLS command can be used the clears out the screen buffer. I have begun using the MySQL Command Line Client and unable to sue this command. Does anyone know the MySQL Command Line Client equivalent to CLS?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dragon-itPosted on 2006-02-02 at 13:48:33ID: 15857643

Try typing echo %date% from a Command Prompt.  For me it always returns Thu 02/02/2006 on Windows 2000 though I think you don't get the Thu bit on XP?

If the OS you are running this on gives you what you need already and youknow it isn't going to change it's output or language etc. you could do away with some of the code, i.e.

REM This is based on the %date% command returning ddd dd/mm/yyyy
REM If yours returns mm/dd/yyyy then swap over the day and month lines

set dayname=%date:~0,3%
set day=%date:~4,2%
set month=%date:~7,2%
set year=%date:~10,4%
set yy=%date:~12,2%

if %dayname%==Mon set daynamefull=Monday
if %dayname%==Tue set daynamefull=Tuesday
if %dayname%==Wed set daynamefull=Wednesday
if %dayname%==Thu set daynamefull=Thursday
if %dayname%==Fri set daynamefull=Friday
if %dayname%==Sat set daynamefull=Saturday
if %dayname%==Sun set daynamefull=Sunday

if %month%==01 set monthname=January& set shortmonthname=Jan
if %month%==02 set monthname=February& set shortmonthname=Feb
if %month%==03 set monthname=March& set shortmonthname=Mar
if %month%==04 set monthname=April& set shortmonthname=Apr
if %month%==05 set monthname=May& set shortmonthname=May
if %month%==06 set monthname=June& set shortmonthname=Jun
if %month%==07 set monthname=July& set shortmonthname=Jul
if %month%==08 set monthname=August& set shortmonthname=Aug
if %month%==09 set monthname=September& set shortmonthname=Sep
if %month%==10 set monthname=October& set shortmonthname=Oct
if %month%==11 set monthname=November& set shortmonthname=Nov
if %month%==12 set monthname=December& set shortmonthname=Dec

echo %daynamefull% %day% %monthname% %year%
echo %dayname% %day% %shortmonthname% %yy%

 

by: simonprrPosted on 2006-02-02 at 14:07:00ID: 15857846

Thanks, but I need this script to work on any version of Windows no matter how the %date% is formatted. Hence the point of the first section of code where it analyises %date% and calculates the day name.

 

by: SteveGTRPosted on 2006-02-02 at 14:11:31ID: 15857883

There was an adjustment I made to the original code that goes before this line:

set /A dayNum=%dd% + (2 * %mm%) + (3 * (%mm% + 1) / 5) + %yyyy% + (%yyyy% / 4) - (%yyyy% / 100) + (%yyyy% / 400) + 1

Here it is:

if /I %mm% LSS 3 set /a mm+=12&set /a yyyy-=1

Good Luck,
Steve

 

by: simonprrPosted on 2006-02-02 at 14:28:54ID: 15858008

Can you explain what that does please Steve?

Will it be future proof for FOREVER?!

 

by: SteveGTRPosted on 2006-02-02 at 14:31:59ID: 15858035

Can't say if it will work forever... The bit of code I added was left out of the original formula.

 

by: simonprrPosted on 2006-02-02 at 14:34:51ID: 15858065

So if the month is less than 3 it adds 12 to the month and goes back 1 year... that right?

How does that find the right dayname?

 

by: SteveGTRPosted on 2006-02-02 at 14:39:44ID: 15858112

You are correct. You'll have to look up the formula. Look at the prior question, I believe I posted links. Otherwise do a search on google. Got to run.

 

by: simonprrPosted on 2006-02-02 at 14:47:46ID: 15858174

I have done some searches, but can't find anything about this particular script.

I've tried it now and the month is coming out at 14! So something aint right.

 

by: SteveGTRPosted on 2006-02-02 at 20:32:19ID: 15860119

Did you implement my update correctly? Here's the first part of your code with the change:

@echo off
REM cls
REM setlocal ENABLEDELAYEDEXPANSION

set yyyy=
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
 for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
    set %%x=%%u
    set %%y=%%v
    set %%z=%%w
    set $d1=
    set $tok=))
if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100
set /A dd=1%dd% - 100
set /A mm=1%mm% - 100

if /I %mm% LSS 3 set /a mm+=12&set /a yyyy-=1

set /A dayNum=%dd% + (2 * %mm%) + (3 * (%mm% + 1) / 5) + %yyyy% + (%yyyy% / 4) - (%yyyy% / 100) + (%yyyy% / 400) + 1
set /A dayNum=%dayNum% %% 7

echo dayNum=%dayNum%

Today, it displays the correct number 4.

 

by: For-SoftPosted on 2006-02-03 at 00:05:38ID: 15860905

You need the script to work on any windows version. Is the old windows 9x and ME included?
If so, this solution will not work on the old windows versions.

 

by: simonprrPosted on 2006-02-03 at 07:53:22ID: 15864470

Steve, which variables should I be using as the output ones then? There is so many used it's hard to know.
For-Soft, sorry I meant I need it to work on new Windows versions - 2000/XP/2003/(Vista!) plus any that have a differently formated %date%

 

by: SteveGTRPosted on 2006-02-03 at 11:03:07ID: 15866489

You can use:

yyyy
dd
mm
dayNum

 

by: simonprrPosted on 2006-02-03 at 12:00:01ID: 15867213

Well that doesn't work here...

I get:

-------------
dayNum=5
03/02/2006
2005
3
14
-------------

From running with the variables echo'ed:

----------------------------------------------------------------------------------
@echo off
REM cls
REM setlocal ENABLEDELAYEDEXPANSION

set yyyy=
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
 for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
    set %%x=%%u
    set %%y=%%v
    set %%z=%%w
    set $d1=
    set $tok=))
if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100
set /A dd=1%dd% - 100
set /A mm=1%mm% - 100

if /I %mm% LSS 3 set /a mm+=12&set /a yyyy-=1

set /A dayNum=%dd% + (2 * %mm%) + (3 * (%mm% + 1) / 5) + %yyyy% + (%yyyy% / 4) - (%yyyy% / 100) + (%yyyy% / 400) + 1
set /A dayNum=%dayNum% %% 7

echo dayNum=%dayNum%
echo %date%
echo %yyyy%
echo %dd%
echo %mm%
----------------------------------------------------------------------------------

 

by: simonprrPosted on 2006-02-03 at 12:02:17ID: 15867241

I did think of setting the dd mm and yyyy variables to other variables before the new line, which does work, but trouble is that I want this to be as flexible as possible so I dont have to fix it every year.

 

by: SteveGTRPosted on 2006-02-03 at 12:11:22ID: 15867335

Yes, I see. We'll have to preserve the mm and yyyy variable so you can use them later.

@echo off

set yyyy=
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
 for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
    set %%x=%%u
    set %%y=%%v
    set %%z=%%w
    set $d1=
    set $tok=))
if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100
set /A dd=1%dd% - 100
set /A mm=1%mm% - 100

set wmm=%mm%
set wyyyy=%yyyy%

if /I %wmm% LSS 3 set /a wmm+=12&set /a wyyyy-=1

set /A dayNum=%dd% + (2 * %wmm%) + (3 * (%wmm% + 1) / 5) + %wyyyy% + (%wyyyy% / 4) - (%wyyyy% / 100) + (%wyyyy% / 400) + 1
set /A dayNum=%dayNum% %% 7

echo dayNum=%dayNum%
echo Date: %date%
echo Year: %yyyy%
echo Day: %dd%
echo Month: %mm%

 

by: SteveGTRPosted on 2006-02-03 at 12:13:02ID: 15867354

Hey, if you want to make sure it works for every date and every year (within reason) why don't you hardcode the values and test it?

 

by: SteveGTRPosted on 2006-02-03 at 12:15:00ID: 15867375

Remember that we do this here for free... You don't pay me anything to do your work. So stop complaining and take some responsibility for the code. I see you've answered some MS-DOS questions so you are no novice. Time to start learning as we all did here and stop whinning. Sorry for being blunt, but my hope is that you'll become a better DOS programmer if you just do a little of the work.

 

by: simonprrPosted on 2006-02-03 at 16:45:01ID: 15870028

Sorry Steve. I wasn't complaining, didn't mean any offence certainly. Thanks anyways.

 

by: K_2KPosted on 2006-02-04 at 05:33:43ID: 15871886

"future proof" for days on "every year possible" indicates knowing the code for leap years ( i don't have it memorized but something like every four years except not every 100 except not every 400 except . . . )   -  the bottom line is a true year is not nothing near a neat and pretty division of days, and some group of people long ago thought this type of adjustment sequence was better than setting the clocks back 6 hours X minutes and X seconds every year.  That would require adjustingworking hours every year but never worry about this being a leap year again.  having handled that little piece we could also re-lable Jan 1st as Monday each year as well.  

oops,  I digress again,  sry,  kinda.  

 My point is, several programs have solved this already, including vbscript, and the vbscript version is not too dificult to pull into DOS batch with a small learning curve.  
(For learning DOS batch, you're better off doing the whole thing with addition and subtraction in set commands and understanding the logic in each line, never forgetting numbers that start with 0 are NOT decimal, etc.  this wheele rewriting helps keep a valuable skill honed for other tasks that have not been pre-solved.)

Anywho,  lemme stop babbleing, poke around a few of my scripts that use vb to get date, and mod one to help a bit  . . .

 

by: K_2KPosted on 2006-02-04 at 06:49:59ID: 15872137

This was easy, and the vb portion is minimal and understandable, but i don't like this version.  
It's kludgy and puts the conversion job in batch instead of VB

I didn't even finish this,  you have to copy the two lines from the weekday conversion to the month setting and change "1 Monday" to "1 January" and so forth.

I include it as an alternative for those who like mostly DOS, while i prefer to rewrite a version that uses the VB conversions that are faster, and also allow DOS to call the script only once.  Your virus checkers will like that better. (this version took a second or two on my machine and i feel that's the time to scan the temporary vbscript as it started up 7 times)

so,  you play with this or wait a bit for my second attempt:


:: dateas.bat
:: return date as day, date, month, etc
:: this is an re-usable example, not a finished product
:: i've prepended all my variables with t to help prevent conflicts with yours
::
:: you must skip to the "start" line, delete what you don't need and
:: re-adjust what you do need to fit your program.
::
@echo off
setlocal


:: setup - done once at the top
set tscript=%temp%\%~n0.vbs
set tget=cscript -nologo "%tscript%"
set tbatch=%temp%\%~n0_A.bat
:: write the vbscript to get time and difference - XP/2K/NT/9x all the same
>"%tscript%" echo sInterval = wscript.arguments^(0^)
>>"%tscript%" echo wscript.echo DatePart^(sInterval, now^)


:: time setup complete, include your own job setups here


:: subroutines here
goto :start

:setconversions
if "%1"=="%2" set thisis=%3
goto :EOF

:: end of subroutines

:start
for /f %%K in ('%tget% w') do set daynamefull=%%K
::convert 1 to Sunday, etc
for %%K in ("1 Sunday" "2 Monday" "3 Tuesday" "4 Wednesday" "5 Thursday" "6 Friday" "7 Saturday") do call :setconversions %daynamefull% %%~K
set daynamefull=%thisis%

for /f %%K in ('%tget% d') do set day=%%K

for /f %%K in ('%tget% m') do set monthname=%%K
::convert month 1 to Jan, etc

for /f %%K in ('%tget% yyyy') do set year=%%K
for /f %%K in ('%tget% h') do set hour=%%K
for /f %%K in ('%tget% m') do set minute=%%K
for /f %%K in ('%tget% s') do set second=%%K


echo %daynamefull% %day% %monthname% %year% %hour%:%minute%:%second%
pause


 

 

by: K_2KPosted on 2006-02-04 at 07:21:11ID: 15872252

as i thought,  this is MUCH cleaner, allowing the vb functions to do the convert, even though it makes the vb part longer, and requires DOS to take in a specific format.
Note that a one line vbscript  (wscript.echo now) would also give DOS a date and time to work with, EXCEPT: Like the built in DOS dates and times, the regional registry and "Shortdate format" changeable in the control panel effect the output format of the now function making it different for different users on the same machine, so we're back again to string compares and gymnastics to straighten it out.  by streatching the vbscript out long enough to force a desired format, the DOS part becomes also much simpler to use.

Enjoy (\o/)

:: dateas.bat
:: return date as day, date, month, etc
:: this is an re-usable example
:: i've prepended all my variables with t to help prevent conflicts with yours
::
:: you must skip to the "start" line, delete what you don't need and
:: re-adjust what you do need to fit your program.
::
@echo off
setlocal

:: setup - done once at the top
set tscript=%temp%\%~n0.vbs
set tget=cscript -nologo "%tscript%"
set tbatch=%temp%\%~n0_A.bat
:: write the vbscript to get time and difference - XP/2K/NT/9x all the same
>"%tscript%" echo dTemp = now
>>"%tscript%" echo wscript.echo weekdayname ^( weekday ^( dTemp ^) ^) _
>>"%tscript%" echo      ^& " " ^& day ^( dtemp ^) _
>>"%tscript%" echo      ^& " " ^& monthname ^( month ^( dtemp ^) ^) _
>>"%tscript%" echo      ^& " " ^& year ^( dtemp ^) _
>>"%tscript%" echo      ^& " " ^& hour ^( dtemp ^) _
>>"%tscript%" echo      ^& " " ^& minute ^( dtemp ^) _
>>"%tscript%" echo      ^& " " ^& second ^( dtemp ^)

:: time setup complete, include your own job setups here


:start
for /f "tokens=1-7" %%K in ('%tget% weekday') do (
   set daynamefull=%%K
   set day=%%L
   set monthname=%%M
   set year=%%N
   set hour=%%O
   set minute=%%P
   set second=%%Q
   )

echo %daynamefull% %day% %monthname% %year% %hour%:%minute%:%second%
pause


 

by: K_2KPosted on 2006-02-04 at 08:01:13ID: 15872421

ERROR in semantics !

Please change this one comment line:
:: write the vbscript to get time and difference - XP/2K/NT/9x all the same
to this one line instead:
:: write the vbscript to get time in a specific format

This above does NOT work in Windows 9x.
This above does NOT calculate differences.

Sorry, The first 5 lines of setup, I copied from a longer script to re-use the auto-nameing of temp files from another utility I wrote.  I did not include here the DOS SET commands into the vbscript that would allow you to call it with Windows 9x redirected to a temp and then run the temp to set the variables. Windows 9x does not understand FOR /F so this script fails there.

thanks (\o/),
2K

 

by: SteveGTRPosted on 2006-02-04 at 09:07:54ID: 15872728

Thanks simonprr, I was a little stressed at work. I need to learn more patience... Sorry :)

 

by: simonprrPosted on 2006-02-04 at 11:17:14ID: 15873271

No problem Steve, I know the feeling.

K_2K: Wow, this looks awesome! I'll check it out and let you know how I get on. Thanks!

 

by: simonprrPosted on 2006-02-05 at 19:17:03ID: 15880210

K_2K, well, I've tested both of your scripts and they work nicely. I'm a litle confused with a few things, wonder if you can help....

Script1 and 2 both output basically the same info, what is really the difference between them? Both of them generate a VB script to do the job?

Are you saying that Script 2 is now fool proof and works everything out from whatever the date format is set in control panel? ie. it will work with any format of day/date and any year (even leap years)?

Can you explain Script 2 a little bit... I see that it creates the vb script to put the date info, but where it run it?
Is that this line:  set tget=cscript -nologo "%tscript%"

And whats this line for?:
set tbatch=%temp%\%~n0_A.bat
I don't see it create that bat file ?!

Cool stuff though, thanks :)

 

by: K_2KPosted on 2006-02-06 at 03:50:21ID: 15881828

script one allows DOS to send the VBscript a parameter and get back different info - so all the outputs datepart show are available without changing the vbscript prt.  
You could save the temp file it makes to a utiliity name and reuse it across several batch files without re-writing the vbs every time.  That one does gives you months 1-12 unless you added the DOS to convert that, and runs MUCH slower on machines that stop the subscript to virus check it each time - it's restarting vb for each item DOS asks for.

For Script two, if you want to get the week of the year, or  the Julian date or something, you have to modify the vbscipt part in setup.  The vbs part only runs once and spits out a specific line coded the way you need it, letting DOS set each word to a part. I like it much better cause I can easily change the vb part to give instead the final result I want to use in DOS, use "delims=" in the FOR /F, and only one DOS variable for the date.  Those who do not want to mess with vbs would probably prefer the first, longer, bulkier code.

<<<tbatch
so right you are, thanks for noticing - it too was the second temporary batch file i used in my windows 98 version. You can delete that line, OR for windows 98 users, modify the vbs to output a line that says "set dosdate= weekdayname ... " then redirect it to file "%tbatch%" then CALL "%tbatch%" to actually set the variable.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...