writing current date & time as file name using NSIS
Asked Answered
A

4

11

I developed an installer using NSIS. Every time I re-install the application, I want to create a backup of the existing database files.

How can I rename these database files using the following format 'currentdatetime'(ex: 201003101140 means 2010-03-10 at 11:40 AM)?

Thanks !

Andi answered 9/3, 2010 at 8:16 Comment(0)
O
20

There is a built-in function in NSIS for this called ${GetTime}

  !include "FileFunc.nsh"
  !insertmacro GetTime

  ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
  DetailPrint "currentdatetime=$2$1$0$4$5$6"

This will output something like

  currentdatetime=20130210205537

meaning "10-Feb-2013 20:55:37".

Orlandoorlanta answered 10/2, 2013 at 20:7 Comment(0)
P
6
System::Call '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2)i.s'
System::Call /NOUNLOAD 'kernel32::GetLocalTime(isr0)'
System::Call '*$0(&i2.r1,&i2.r2,&i2,&i2.r3,&i2.r4,&i2.r5,&i2,&i2)'
System::Free $0
IntFmt $1 "%0.4d" $1
IntFmt $2 "%0.2d" $2
IntFmt $3 "%0.2d" $3
IntFmt $4 "%0.2d" $4
IntFmt $5 "%0.2d" $5
DetailPrint "datetime=$1$2$3$4$5"
Phelgen answered 9/3, 2010 at 15:47 Comment(0)
S
6

The best way to do this is explained here: nsis !define /date MyTIMESTAMP "%Y-%m-%d-%H-%M-%S" Name "MyApplicationName ${MyTIMESTAMP}" OutFile "MyApplicationNameSetup-${MyTIMESTAMP}.exe"

Sik answered 4/1, 2017 at 14:58 Comment(2)
This is a compile time command, not runtime, so the date given by ${MyTIMESTAMP} will be that of the build not when run. This will not work to create a backup folder.Magnification
This was exactly what I looked forEtem
A
-1

These macros might work for you: http://nsis.sourceforge.net/Docs/Chapter5.html#5.2.3

Asymptomatic answered 10/3, 2010 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.