Link to home
Start Free TrialLog in
Avatar of Champ MUC
Champ MUC

asked on

How to rename a file with this format DDMMYYY_HHam/pm_Filename.xls <----- Date and time is converted from SGT to GMT

Hi Experts,

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 DDMMYYY_HHam/pm_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.

  @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"



Thanks in advance!! :)
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I don't know the complete answer to your question but I do know that using 'DDMMYYY' format will not sort in date order.  I use 'YYYYMMDD' when I need the names to sort properly.
Avatar of Champ MUC
Champ MUC

ASKER

Hi Dave,

Thanks, format is not really a big issue at all, only the date and time should be in Irish time (Another Timezone) and if possible, can you teach me how to set format of date and time to 2 digits? I am getting 1/6/2017 6AM, I want something like 01/06/2017 06AM..

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial