0

I just wan to seek help, im not really a programmer but I came across the need for this for one project. Is there a way for a batch file or script to rename a file with the format like this HHam/pm_YYYYDDMM_Filename.xls (am/pm is interchangeable), the tricky part is the date and time should be converted to GMT Timezone, I am on SGT timezone right now so I cannot use the time from my local machine.

I'm using this script to rename it but I'm having issues with the date and time changing from single digit to double digit which requires the percentage % to be change. If you can help me just to set the date and time to double digit. This gets code gives this format 2017/1/6 6:00:00AM but what i want is 2017/01/06 06:00 AM

@echo off
set TmpFile="%temp%.\tmp.vbs"
echo> %TmpFile% n=Now
echo>>%TmpFile% s=DateAdd("h", -7, n)
echo>>%TmpFile% Wscript.Echo "set ireland7=" ^& s
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
call "%temp%.\tmp.bat"
del  "%temp%.\tmp.bat"
del  %TmpFile%
copy "D:\Data\Hourly_Report\HourlyFile\voucher_last_hour.xls" "D:\Data\Hourly_Report\%ireland7:~0,2%-%ireland7:~3,1%-%ireland7:~5,4%_%ireland7:~10,2%%ireland7:~19,17%_Hourly_Report.xls"
aschipfl
  • 28,946
  • 10
  • 45
  • 77
Champ14
  • 1
  • 1
  • 1
    `echo>>%TmpFile% Wscript.Echo "set ireland7=" ^& FormatDateTime(s,0)` however you can parse `wmic path Win32_UTCTime get` using `for /F` for pure batch solution. – JosefZ Jun 01 '17 at 07:11
  • 2
    Possible duplicate of [How to get current datetime on Windows command line, in a suitable format for using in a filename?](https://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us) – aschipfl Jun 01 '17 at 07:55

0 Answers0