PC Review


Reply
Thread Tools Rate Thread

How to add yesterday's date to a filename if/when a job is run after midnight.

 
 
ajmister
Guest
Posts: n/a
 
      26th Nov 2007
Hi

I have a job that is dependant on the successful completion of another
script. Therefore the job could run before or after midnight.

If the job runs before midnight my adddate script address today's date
(YYYYMMDD) to the filename. I am having trouble with the adddate script when
the job runs after midnight. If the job runs after midnight I would like the
script to add yesterday's date to the filename but it is adding current days
date.

Does anyone have suggestions.

Ajmister.


 
Reply With Quote
 
 
 
 
foxidrive
Guest
Posts: n/a
 
      27th Nov 2007
On Mon, 26 Nov 2007 16:34:04 -0500, "ajmister" <(E-Mail Removed)> wrote:

> I have a job that is dependant on the successful completion of another
>script. Therefore the job could run before or after midnight.
>
> If the job runs before midnight my adddate script address today's date
>(YYYYMMDD) to the filename. I am having trouble with the adddate script when
>the job runs after midnight. If the job runs after midnight I would like the
>script to add yesterday's date to the filename but it is adding current days
>date.
>
> Does anyone have suggestions.



Date foward & backward

@echo off
:: from code by Phil Robyn
setlocal
if [%1]==[] (
echo to get todays date use
echo call "%~n0" today 0
echo.
echo to get yesterdays date use
echo call "%~n0" today -1
echo.
echo to get the date 25 days ago:
echo call "%~n0" today -25
echo.
echo to get the date 1250 days in the future
echo call "%~n0" today +1250
goto :EOF)

set date1=%1
set qty=%2
if /i "%date1%" EQU "TODAY" (
set date1=now
) else (
set date1="%date1%"
)
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%-%result:~4,2%-%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)


 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      27th Nov 2007

"ajmister" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I have a job that is dependant on the successful completion of another
> script. Therefore the job could run before or after midnight.
>
> If the job runs before midnight my adddate script address today's date
> (YYYYMMDD) to the filename. I am having trouble with the adddate script
> when the job runs after midnight. If the job runs after midnight I would
> like the script to add yesterday's date to the filename but it is adding
> current days date.
>
> Does anyone have suggestions.
>
> Ajmister.
>
>


Since you haven't shown us your adddate script, so adjusting it may be a
little difficult.

How about generating the filename that you require within the first script
which I assume is scheduled to start before midnight? Then pass the filename
or pre-midnight date to the second script, either as a parameter or via a
file?


 
Reply With Quote
 
Todd Vargo
Guest
Posts: n/a
 
      28th Nov 2007

"ajmister" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I have a job that is dependant on the successful completion of another
> script. Therefore the job could run before or after midnight.
>
> If the job runs before midnight my adddate script address today's date
> (YYYYMMDD) to the filename. I am having trouble with the adddate script

when
> the job runs after midnight. If the job runs after midnight I would like

the
> script to add yesterday's date to the filename but it is adding current

days
> date.
>
> Does anyone have suggestions.


Post your adddate script and tell us at what time you want to stop back
dating.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

 
Reply With Quote
 
ajmister
Guest
Posts: n/a
 
      28th Nov 2007
Hi
Here is my add date script.

echo off
for /F "tokens=1,2,3" %%r in ('date /t') do (
for /f "tokens=1,2,3 delims=/" %%c in ("%%s") do set filedte=%%e%%c%%d
)
echo %filedte%

ren coverage.txt coverage.txt_%filedte%

If the script runs after midnight I need my script to pick previous day's
date instead of current day's date. My script runs anytime between 10 pm and
6 am the next day.

Thank you.

Aj

"Todd Vargo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "ajmister" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> I have a job that is dependant on the successful completion of
>> another
>> script. Therefore the job could run before or after midnight.
>>
>> If the job runs before midnight my adddate script address today's
>> date
>> (YYYYMMDD) to the filename. I am having trouble with the adddate script

> when
>> the job runs after midnight. If the job runs after midnight I would like

> the
>> script to add yesterday's date to the filename but it is adding current

> days
>> date.
>>
>> Does anyone have suggestions.

>
> Post your adddate script and tell us at what time you want to stop back
> dating.
>
> --
> Todd Vargo
> (Post questions to group only. Remove "z" to email personal messages)
>



 
Reply With Quote
 
foxidrive
Guest
Posts: n/a
 
      28th Nov 2007
On Wed, 28 Nov 2007 09:50:18 -0500, "ajmister" <(E-Mail Removed)> wrote:

> Here is my add date script.
>
>echo off
>for /F "tokens=1,2,3" %%r in ('date /t') do (
>for /f "tokens=1,2,3 delims=/" %%c in ("%%s") do set filedte=%%e%%c%%d
>)
>echo %filedte%
>
>ren coverage.txt coverage.txt_%filedte%
>
>If the script runs after midnight I need my script to pick previous day's
>date instead of current day's date. My script runs anytime between 10 pm and
>6 am the next day.



To figure out which day it is use the time and see if it is before 10, and run
an appropriate routine.

Use %day% which will be populated with the result EG: 2007-11-28


@echo off
for /f "delims=:" %%a in ("%time%") do if %%a LSS 10 (
set qty=-1
call :getdate
) else (
set qty=0
call :getdate
)
echo %%day%% is set to "%day%"
goto :EOF
:getdate
set date1=now
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
set day=%result:~0,4%-%result:~4,2%-%result:~6,2%



If you are unable to use WSH then here is a thread that could help you:

http://groups.google.com.au/group/al...883858bfaf0fa5

 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      28th Nov 2007

"ajmister" <(E-Mail Removed)> wrote in message
news:ecDk$(E-Mail Removed)...
>
> "Todd Vargo" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> "ajmister" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi
>>>
>>> I have a job that is dependant on the successful completion of
>>> another
>>> script. Therefore the job could run before or after midnight.
>>>
>>> If the job runs before midnight my adddate script address today's
>>> date
>>> (YYYYMMDD) to the filename. I am having trouble with the adddate script

>> when
>>> the job runs after midnight. If the job runs after midnight I would like

>> the
>>> script to add yesterday's date to the filename but it is adding current

>> days
>>> date.
>>>
>>> Does anyone have suggestions.

>>
>> Post your adddate script and tell us at what time you want to stop back
>> dating.
>>
>> --
>> Todd Vargo
>> (Post questions to group only. Remove "z" to email personal messages)
>>

>


> Hi
> Here is my add date script.
>
> echo off
> for /F "tokens=1,2,3" %%r in ('date /t') do (
> for /f "tokens=1,2,3 delims=/" %%c in ("%%s") do set filedte=%%e%%c%%d
> )
> echo %filedte%
>
> ren coverage.txt coverage.txt_%filedte%
>
> If the script runs after midnight I need my script to pick previous day's
> date instead of current day's date. My script runs anytime between 10 pm
> and 6 am the next day.
>
> Thank you.
>
> Aj
>


Ah - the dentist scenario...

The format of the "date/t" command varies depending on the setting for the
user under whose account the job is run.

We can conclude that the date format you are using is month/daynumber/year
from this data.

We now have "THE script" but you're not specific as to whether THE script to
which you refer is THIS script or THIS script's CALLER. It seems odd that a
script could be run at a random time between 10pm and 6am, but you offer no
description of why this might be.

So - next step is to determine what the format of TIME/t might be for your
machine. It also conveniently depends on user settings. Mine is in 24-hour
format, but yours may be in 12-hour format, may or may not have leading
zeroes on the hour, and may also have a separator other than ":" (although
that seems unlikely)

Once we know your TIME format, we can construct a scheme to subtract 1 day
if the time is after midnight, so examples of your TIME format would be
useful.

I'll not approach the method for performing the maths yet - the trick is to
recognise the 1st of the month and leap years. Done many times before - and
posted in Timo Salmi's FAQ in alt,msdos.batch.nt, but the key for this
mysterious application is the time - the date-manipulation is the easy
part....

For your existing script though,

for /F "tokens=2,3,4 delims=/ " %%c in ('date /t') do set filedte=%%e%%c%%d
echo %filedte%

would seem to be a worthwhile simplification. Note the SPACE afer the / in
the DELIMS list which makes delimiters "/" OR [space]



 
Reply With Quote
 
Todd Vargo
Guest
Posts: n/a
 
      29th Nov 2007

"foxidrive" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Wed, 28 Nov 2007 09:50:18 -0500, "ajmister" <(E-Mail Removed)>

wrote:
>
> > Here is my add date script.
> >
> >echo off
> >for /F "tokens=1,2,3" %%r in ('date /t') do (
> >for /f "tokens=1,2,3 delims=/" %%c in ("%%s") do set filedte=%%e%%c%%d
> >)
> >echo %filedte%
> >
> >ren coverage.txt coverage.txt_%filedte%
> >
> >If the script runs after midnight I need my script to pick previous day's
> >date instead of current day's date. My script runs anytime between 10 pm

and
> >6 am the next day.

>
>
> To figure out which day it is use the time and see if it is before 10, and

run
> an appropriate routine.


Actually, the backdate routine only needs to detect if the time is between
midnight and 6am.

The following batch returns the desired date in YYYYMMDD format.

@echo off
echo >"%temp%\%~n0.vbs" s=Now
echo>>"%temp%\%~n0.vbs" If Hour(s) ^> 6 Then s=s-1
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set day=%%a
del "%temp%\%~n0.vbs"
echo %%day%% is set to "%day%"

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

 
Reply With Quote
 
foxidrive
Guest
Posts: n/a
 
      29th Nov 2007
On Wed, 28 Nov 2007 23:32:22 -0500, "Todd Vargo" <(E-Mail Removed)>
wrote:

>Actually, the backdate routine only needs to detect if the time is between
>midnight and 6am.
>
>The following batch returns the desired date in YYYYMMDD format.
>
>@echo off
>echo >"%temp%\%~n0.vbs" s=Now
>echo>>"%temp%\%~n0.vbs" If Hour(s) ^> 6 Then s=s-1


did you mean < 6 ??

>echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
>echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
>echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
>for /f %%a in (
> 'cscript //nologo "%temp%\%~n0.vbs"') do set day=%%a
>del "%temp%\%~n0.vbs"
>echo %%day%% is set to "%day%"


 
Reply With Quote
 
Todd Vargo
Guest
Posts: n/a
 
      29th Nov 2007

"foxidrive" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Wed, 28 Nov 2007 23:32:22 -0500, "Todd Vargo" <(E-Mail Removed)>
> wrote:
>
> >Actually, the backdate routine only needs to detect if the time is

between
> >midnight and 6am.
> >
> >The following batch returns the desired date in YYYYMMDD format.
> >
> >@echo off
> >echo >"%temp%\%~n0.vbs" s=Now
> >echo>>"%temp%\%~n0.vbs" If Hour(s) ^> 6 Then s=s-1

>
> did you mean < 6 ??


Good catch!

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for the date after midnight navin Microsoft Access 4 29th Nov 2007 05:26 PM
Inbox - Sort - Date: Today Date: Yesterday Jan Groshan Microsoft Outlook 2 24th Apr 2006 09:23 PM
search date -7 from midnight to current date 23:59 =?Utf-8?B?am9qbw==?= Microsoft Outlook Discussion 0 18th Feb 2005 03:49 PM
Date/Time field - midnight Mary Microsoft Access Queries 5 4th Feb 2005 07:31 PM
Re: Assigning Date value to Date/Time field (=midnight?) John Spencer (MVP) Microsoft Access VBA Modules 1 8th Aug 2003 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 AM.