Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Date and time properties - formatting

Using AI 7.7:
I want to backup a directory before I install.
I want to backup this directory for example, to c:\backup\2010_06_24\
which means: year 2010, month 06 (june) and day 24 (today).
I might also want to add the current time like this:
c:\backup\2010_06_24__17_11_02\

But the date and time properties are not formatted like I want....
The date property is: "6/24/2010"
and the time property is: "17:11:02"

So my questions are:
1. how do I format it to be like I want?
2. When should I do the backup? meaning: obviously not in the "install" phase, since by then: all NEW files have been already copied!
3. Do I have to use a custom command to do that? like:

Code: Select all

       xcopy "c:\program files\myproject\config\*.*" "c:\backup\2010_06_24__17_11_02\"
      
or can I do it in some other way using AdvancedInstaller?

Thanks for all, Dashut.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Date and time properties - formatting

Hi Dashut,

1) Easiest approach is using a bat file. In batch scripting, you can format the date. Write the below code in a console and see date formatting in action:

Code: Select all

echo %date%
echo %date:~10,4%.%date:~4,2%.%date:~7,2%
basically, %date:~10,4% means the date environment variable's value from 10th position, 4 letters in size (that's the year). The dot will simply be part of the resulting string. You can replace it
with an underscore in your case.

2) The backup can be done anywhere before InstallFiles if your backup script is deferred and anywhere before InstallExecute if your script is immediate.

3) Placing everything in a bat file and adding that as a custom action would be the easiest approach. You can then use xcopy in your script to backup the data.

You might also want to hide the command window that pops up when the installer is executing the batch file. See our guide on hiding it.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Date and time properties - formatting

I've tested this, and it works (batch file).
My question is (since I'm not good with VBScript at all...):
How do I run a VBScript that created this date say: "2010_07_30" and stores it in a Windows Installer Property? Then I can use this property in my custom action! This will be great!

Many thanks, Dashut.
Bogdan
Posts: 2791
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Date and time properties - formatting

Hi Dashut,

Here is VBScript sample for your guidance:

Code: Select all

' BEGIN SAMPLE 

' custom date string placed in a MSI public property
' Author -- Mitrache Bogdan

dateVariable  = Date ' get the date from the OS

' parse the date retrieved
yearVariable  = Year(dateVariable)
monthVariable = Month(dateVariable)
dayVariable   = Day(dateVariable)

lineChar = "_"

' create the string that will be placed in the property
propertyValue = yearVariable & lineChar & monthVariable & lineChar & dayVariable

' set the public property "MY_PROP" to the value of the variable "propertyValue"
Session.Property("MY_PROP") = propertyValue

' END SAMPLE
Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Date and time properties - formatting

I saved what you offered in a file named: dateset.vbs
I also added a function name (like I saw in other places... forgive me, but I really don't know VBS, just C++ for now...).
So here's how that file looks like (dateset.vbs):

Code: Select all

Function TestDate()
' BEGIN SAMPLE 

' custom date string placed in a MSI public property
' Author -- Mitrache Bogdan

dateVariable  = Date ' get the date from the OS

' parse the date retrieved
yearVariable  = Year(dateVariable)
monthVariable = Month(dateVariable)
dayVariable   = Day(dateVariable)

lineChar = "_"

' create the string that will be placed in the property
propertyValue = yearVariable & lineChar & monthVariable & lineChar & dayVariable

' set the public property "MY_PROP" to the value of the variable "propertyValue"
Session.Property("MY_PROP") = propertyValue

' END SAMPLE
End Function

now I run this with:
Type: File installed with the procluct.
Source Path: APPDIR\dateset.vbs
Source Type: Visual basic script (*.vbs)
Function name: TestDate
Action Data:

I also tried to create the Property "MY_PROP" by adding it to the "Search" (just to give it some default registry value so that it exists).
But then I get the following error (taken from the msi log):

Code: Select all

Action 13:08:43: RunDateSetScript. 
MSI (s) (E8:40) [13:08:43:093]: Executing op: CustomActionSchedule(Action=RunDateSetScript,ActionType=1110,Source=C:\Program Files\Your Company\Your Application\dateset.vbs,Target=TestDate,)
MSI (s) (E8:60) [13:08:43:140]: Note: 1: 1720 2: RunDateSetScript 3: -2147467259 4: Msi API Error 5: Property,Name 6: 20 7: 1 
What am I doing wrong here?

Thanks again, Dashut.
Bogdan
Posts: 2791
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Date and time properties - formatting

Hi,

Could you please send me the aip file to support at advancedinstaller dot com?

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Date and time properties - formatting

Using AI 7.7:
I started with a NEW Enterprise project and it worked!

Here's the code I used:

Code: Select all

Function BackupTime()
' custom date string placed in a MSI public property
' Author -- Mitrache Bogdan
Dim yearVariable, monthVariable, dayVariable, lineChar, propertyValue

yearVariable  = Year(Now())
monthVariable = Month(Now())
dayVariable   = Day(Now())
hourVariable   = Hour(Now())
minuteVariable   = Minute(Now())
secondVariable   = Second(Now())

lineChar = "_"

' create the string that will be placed in the property
propertyValue = yearVariable & lineChar & monthVariable & lineChar & dayVariable & lineChar & lineChar & hourVariable & lineChar & minuteVariable & lineChar & secondVariable

' set the public property "BACKUP_TIME" to the value of the variable "propertyValue"
Session.Property("BACKUP_TIME")=propertyValue

End Function
Thank you very much for your time, Dashut.
Collins
Posts: 138
Joined: Wed Oct 12, 2016 2:57 pm

Re: Date and time properties - formatting

I'm trying to reuse this to set a date for a property in the UI on the Next button:

Code: Select all

Function ProcessFromTime()
' custom date string placed in a MSI public property
' Author -- Mitrache Bogdan
Dim yearVariable, monthVariable, dayVariable, propertyValue

yearVariable  = DateAdd("YYYY",-2,Now())
monthVariable = Month(Now())
dayVariable   = Day(Now())


' create the string that will be placed in the property
propertyValue = yearVariable & monthVariable & dayVariable

' set the public property "MINDATEPROCESS" to the value of the variable "propertyValue"
Session.Property("MINDATEPROCESS")=propertyValue

End Function
it should get the current year, minus 2 years and the month\date and put it in the MINDATEPROCESS=20160126. I have it set as an inline script in the Wizard Dialog stage without sequence, but when it runs, it doesn't add a value to the property.
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Date and time properties - formatting

Hi,

In the VBS code you attached, the "ProcessFromTime()" function is only defined, but it is not called. In order to call that function for the date to be processed, you need to write it at the end of your code after the "End Function" line (e.g. "ProcessFromTime()").

Let me know if this helped.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Collins
Posts: 138
Joined: Wed Oct 12, 2016 2:57 pm

Re: Date and time properties - formatting

That's what it was...Thank you.
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Date and time properties - formatting

You're welcome. Glad to help.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”