Computing.Net > Forums > Programming > Batch file problem with date

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file problem with date

Reply to Message Icon

Name: jaymcgovern
Date: October 29, 2008 at 19:42:15 Pacific
OS: xp
CPU/Ram: not sure
Product: windows
Comment:

I have never coded before using batch files and SED and have not coded at all in the last 5 years, but have a screen scraping program that I have been making changes to today. I added the sold_date field and the sale_price field. I got the sale_price field to work but can't get the date_field to work.

Here is the code:

set SOLDDATE=
SET AMOUNT=
set MATCHA=
grep -q "parcelID" ~ustax.htm
if ERRORLEVEL 1 goto __GANOREC
grep parcelID ~ustax.htm|sed "s/""/~/g" |cut -d"~" -f6|sed "1s/^/http\:\/\/www\.ustaxdata\.com\/nc\/wilson\//">~proplink
del ~ustax.htm
wget -q -nd -c -O ~ustax.htm -i ~proplink
sed -n "/Mailing/,/Property/p" ~ustax.htm|sed -n "6s/[<>]/~/gp"|cut -d"~" -f7>~tmp
for /f "delims==" %%R in (~tmp) do set ADDRESS=%%R
sed -n "/Mailing/,/Property/p" ~ustax.htm|sed -n "10s/[<>]/~/gp"|cut -d"~" -f7>~tmp
for /f "delims==" %%R in (~tmp) do set CITY=%%R

sed -n "/Sold/,/Valuation/p" ~ustax.htm|sed -n "2s/[<>]/~/gp"|cut -d"~" -f9>~tmp
for /f "delims==" %%R in (~tmp) do set SOLDDATE=%%R

sed -n "/Sold/,/Valuation/p" ~ustax.htm|sed -n "6s/[<>]/~/gp"|cut -d"~" -f9>~tmp
for /f "delims==" %%R in (~tmp) do set AMOUNT=%%R

And here is the text of one of the webpages it's suppose to scrape

<TD bgcolor="#efefef">Sold Date</TD>
<TD bgcolor="#efefef"><div align="left"><strong></strong><strong>2003-01-31</strong></div></TD>
</TR>
<TR VALIGN=top bgcolor="#efefef">
<TD>Sold Amount $</TD>
<TD><div align="left"><strong>140,000</strong></div></TD>
</TR>
</TABLE>
</TD>
<TD WIDTH="33%">
<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="153A64">
<tr>
<td>Valuation
Information
</td>

TIA




Sponsored Link
Ads by Google

Response Number 1
Name: BatchFreak
Date: October 29, 2008 at 20:27:01 Pacific
Reply:

Am I missing something? Why not just have
Set SoldDATE=%date%

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 2
Name: jaymcgovern
Date: October 30, 2008 at 09:47:48 Pacific
Reply:

I'm trying to bring in dates from the website formatted YYYY-MM-DD, that code is bring in the current date.


0

Response Number 3
Name: BatchFreak
Date: October 30, 2008 at 17:19:10 Pacific
Reply:

Dude im still confused as to what you want... But if you want the date in yyyy-mm-dd format heres the code.

FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
SET date=%yyyy%-%mm%-%dd%
ECHO %date%
pause

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 4
Name: jaymcgovern
Date: October 30, 2008 at 17:24:54 Pacific
Reply:

Not to be ignorant dude, but I don't program. So where would the code go in relationship to the posted code? Up where everything is set or where I'm stripping the date out of the webpage? It's not the format I care about, it's just pulling out the date being displayed on the webpage. I've tried a lot of different things and I can't even get just the year to be written out. Thanks for your response.


0

Response Number 5
Name: BatchFreak
Date: October 30, 2008 at 17:44:05 Pacific
Reply:

Sorry, I gave you the wrong code... Apparently I a bieng ignorant :)


echo. | date | FIND "(mm" > NUL
If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
goto :EOF
:Parse-----
For /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
set %1=%%A&set %2=%%B&set YYYY=%%C
) else (
set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)

(Set DateStamp=%YYYY%-%MM%-%DD%)

Ok you would write this at the very top of your code, and then where you want it to write your date, you simply type. %Datestamp%

I only Batch if possible, 2000 more lines of code, oh well.


0

Related Posts

See More



Response Number 6
Name: BatchFreak
Date: October 30, 2008 at 17:49:17 Pacific
Reply:

... Im not to sure how to pull the date out...

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 7
Name: klint
Date: October 31, 2008 at 11:48:03 Pacific
Reply:

BatchFreak, your revised code still doesn't do what the OP asked, which was to read an HTML file which contains a date somewhere inside it, and process that date (NOT today's date!)

To do that is difficult, so I won't attempt it.


0

Response Number 8
Name: Mechanix2Go
Date: November 1, 2008 at 04:13:03 Pacific
Reply:

"BatchFreak, your revised code still doesn't do what the OP asked,"

It's worse than that, Jim.

There is NO general substring code for %DATE% because the date layouts vary widely.

Somebody might be able to pull the date from the html, if we HAD the html. LOL


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 9
Name: jaymcgovern
Date: November 1, 2008 at 04:41:24 Pacific
Reply:

Here you go M2, let me know if you need the whole page. I copied the HTML from my original post, let me know if you would like, I can send you the entire page.

<TD bgcolor="#efefef">Sold Date</TD>
<TD bgcolor="#efefef"><div align="left"><strong></strong><strong>2003-01-31</strong></div></TD>
</TR>
<TR VALIGN=top bgcolor="#efefef">
<TD>Sold Amount $</TD>
<TD><div align="left"><strong>140,000</strong></div></TD>
</TR>
</TABLE>
</TD>
<TD WIDTH="33%">
<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="153A64">
<tr>
<td>Valuation
Information</td>


0

Response Number 10
Name: Mechanix2Go
Date: November 1, 2008 at 06:02:16 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('find "200" ^< mypage') do (
set str=%%a
)

for /f "tokens=6 delims=<>" %%a in ("!str!") do (
echo %%a
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: BatchFreak
Date: November 1, 2008 at 08:57:38 Pacific
Reply:

I had misunderstood him, I though he wanted todays date to be placed with the file.

I only Batch if possible, 2000 more lines of code, oh well.


0

Sponsored Link
Ads by Google
Reply to Message Icon

New skills shortcut to HELP



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file problem with date

batch file problem with %homepath% www.computing.net/answers/programming/batch-file-problem-with-homepath-/14484.html

Win XP batch file problem www.computing.net/answers/programming/win-xp-batch-file-problem/11239.html

Batch file problem www.computing.net/answers/programming/batch-file-problem/8964.html