Announcement

Collapse
No announcement yet.

Date Variable for yyyymmdd

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Variable for yyyymmdd

    Hi

    I am trying to copy all csv files from a specific share (\\server\logs\yyyymmdd\*.csv) to a local folder on my pc. This is a black berry server and it creates daily log files. The log files are stored in a folder which is created daily in the following format yyyymmdd (no spaces) ex 20071106.
    I need to copy all of the csv files from the daily folder to similar directory structure on my pc. I have bat file which does almost what i need. The problem is the date format is yyyy mm dd and i need it to be yyyymmdd. This is a sample of what i already have. Can some one assist with modifying date format.

    @echo off
    @REM quick date batch
    @REM Setups %date variable
    @REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be YYYYMMDD

    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%

    mkdir "D:\Compliance\Signoff\%date%"

    move "D:\Signoff\*.*" "d:\compliance\signoff\%date%"

    Thanks

  • #2
    Re: Date Variable for yyyymmdd

    To make the creation of the datestamp independed of the OS language,
    you must write a batch that can also determine the date-format;
    Code:
     @echo off
    
      echo. | date | FIND "(mm" > NUL
      If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
      goto :EOF
     :Parsedate ----------------------------------------------------------
      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%)
    
    
    echo DateStamp: %DateStamp%  ( day of the week: %DOW% )
    
    echo.
    pause
    The batch above works on all Windows_NT based OSs


    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Date Variable for yyyymmdd

      Hi Rems

      Thansk for the reply... I tried your code... It creates the date in the following format when i run the script... c:\compliance\sms\Wed 11/07/2007... Which acctually Creates a seperate for for Wed 11, then 07, the folder for 2007... What i really need is a code that will format the date and create the folder (or copy from a folder in this format) yyyymmdd... For ex the Black Berry server creates log files and cretaes a folder for each day... The folder is named yyyymmdd (20071107)... Attached is screenshot of what the Black Berry server creates and what i am looking to mimic...
      Attached Files

      Comment


      • #4
        Re: Date Variable for yyyymmdd

        My batch is doing what you ask - it is setting a %DateStamp% variable,
        its value is always in the format: YYYYMMDD.

        From now do not use the variable %date% in your script (this is by default a system evironment its value is the same as the output of the command Date/T). If you are using my code, you must use the %DateStamp% variable when using mkdir or move

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Date Variable for yyyymmdd

          NICE!!... thanks Rem

          Comment

          Working...
          X