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

Author Topic: Cmd or Program to do ls -lrt | tail -1 as done in Unix  (Read 8997 times)

0 Members and 1 Guest are viewing this topic.

Reno



    Hopeful
  • Thanked: 32
    Re: Cmd or Program to do ls -lrt | tail -1 as done in Unix
    « Reply #15 on: March 30, 2009, 10:58:46 AM »
    2. You want to subtract 1 from e.g. 26 to get 25? Or get the previous day's date?
    I want previous day's date.

    3. Boundry Conditions >> Meaning Month ends / Year conditions to get previous day's date.

    smartjosh, here is the bat way to calculate date difference, source is from wiki, and i haven't tested it throughly, so may still contain bugs. if you did have access to vbscript, it's easier to do it with vbscript.
    Code: [Select]
    ::source: http://en.wikipedia.org/wiki/Julian_day
    @echo off & setlocal
    if "%~1"=="" echo USAGE: %0 [interval] & goto:eof

    for /f "skip=1 tokens=2-4 delims=(./-)" %%a in ('echo.^|date') do (
    for /f "tokens=1-3 delims=./- " %%A in ('echo %date:~-10%') do (
    set %%a=%%A& set %%b=%%B& set %%c=%%C
    ))
    echo Today :%yy%%mm%%dd%
    set/a mm=1%mm%-100,dd=1%dd%-100

    ::jd
    set/a a=(14-mm)/12, y=yy+4800-a, m=mm+12*a-3
    set/a jd=dd+ (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
    ::date interval
    set/a jd+=%~1

    ::gd
    set/a s1=jd+68569, n=4*s1/146097, s2=s1-(146097*n+3)/4, i=4000*(s2+1)/1461001
    set/a s3=s2-1461*i/4+31, q=80*s3/2447, s4=q/11, e=s3-2447*q/80
    set/a yy=100*(n-49)+i+s4, mm=q+2-12*s4, dd=e, gd=yy*10000+mm*100+dd
    echo %1 :%gd%


    test output
    Code: [Select]
    C:\>jd 10
    Today   :20090330
    10      :20090409

    C:\>jd -1
    Today   :20090330
    -1      :20090329

    C:\>jd -1000
    Today   :20090330
    -1000   :20060704