0

From this post, was able to get the file modification date

ECHO Last-Modified Date   : %%~t? 

returns YYYY-MM-DD HH:MM <AM/PM>. 

However, I need it to be in 24 hour format.

How to do that?

TIA!

Stephan
  • 53,940
  • 10
  • 58
  • 91
user2585040
  • 65
  • 2
  • 9
  • One approach would be to add 12 to the hour when the String contains PM – Marged Aug 04 '20 at 22:25
  • @Marged Just adding `12` to the hour on string containing `PM` is wrong for the time range `12:00 PM` to `12:59 PM`. That would be right only for the time range `01:00 PM` to `11:59 PM`. So it would be additionally required to evaluate the value of the hour if being less than `12` before doing the addition with `12`. – Mofi Aug 06 '20 at 16:47

1 Answers1

1

With a batch file you can do something like this :

@echo off
Title Get file modification date in 24 hour format using windows batch file
set "DesktopFolder=%userprofile%\Desktop"
set "Ext=txt"
CD /D "%DesktopFolder%"
Setlocal EnableDelayedExpansion
@FOR /F "delims=" %%A IN ('dir /B "%DesktopFolder%\*.%Ext%" 2^>nul') DO (
    SET /a "Count+=1"
    SET "File[!Count!]=%%~fA"
)

@For /L %%i in (1,1,%Count%) do (
    Call :GetLastModifiedDate "!File[%%i]!" LastModifiedDate
    echo "!File[%%i]!"  "!LastModifiedDate!"
)
Pause & EXIT
::----------------------------------------------------------------------------
:GetLastModifiedDate <File> <LastModifiedDate>
Set "vbsfile=%Temp%\%~n0.vbs"

>"%vbsfile%" (
    echo Set FSO=CreateObject("Scripting.FileSystemObject"^)
    echo WScript.Echo FSO.GetFile("%~1"^).DateLastModified
)
@for /f "delims=" %%a in ('cscript //NoLogo "%vbsfile%"') do Set "%2=%%a"
Exit /B
::----------------------------------------------------------------------------
Hackoo
  • 18,337
  • 3
  • 40
  • 70