VMware Cloud Community
gbeke
Enthusiast
Enthusiast
Jump to solution

Date format in workflow where user selects a date from calendar

Hi,

I'm working on a simple workflow that lets the user select a date.

pastedImage_0.png

The input type is set to date, and when I look at the date in the system log it looks like this "Fri Sep 21 2018 13:17:17 GMT+0200 (CEST)". I only need the date, not the time, and ideally it should be in this format: dd.mm.yyyy.

Iv'e tried using split, but get this message "Cannot find function split in object". I'm guessing I need to convert the date object to a string but I'm struggling to find out how to do that. With a virtual machine object I do it by assigning vm.name to a new variable. I've been unable to find out if I can do the same with date.

Any suggestions on how to accomplish this will be greatly appreciated. I would like to have the user select a date from a calendar if possible, but I'm open to other ways to accomplish this.

Thanks in advance.

GB

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
rwk1982
Enthusiast
Enthusiast
Jump to solution

Hello!

Search in the vRO API Explorer for the Scripting Class "Date":

pastedImage_0.png

For example you can get the year with "YourDateVar.getFullYear()"

Drink coffee.. Do stupid things faster with more energy...

View solution in original post

Reply
0 Kudos
4 Replies
rwk1982
Enthusiast
Enthusiast
Jump to solution

Hello!

Search in the vRO API Explorer for the Scripting Class "Date":

pastedImage_0.png

For example you can get the year with "YourDateVar.getFullYear()"

Drink coffee.. Do stupid things faster with more energy...
Reply
0 Kudos
gbeke
Enthusiast
Enthusiast
Jump to solution

Thanks, Robert.

I keep forgetting about the API explorer. I successfully extracted the desired information using date.getDate(), date.getMonth() and date.getFullYear(). Now I just have to figure out how to pad single digit numbers with a leading zero. Smiley Happy

Reply
0 Kudos
rwk1982
Enthusiast
Enthusiast
Jump to solution

function AddLeadingZero(number) {

     return (number < 10 ? '0' : '') + number

}

var day = date.getDate()

var month = date.getMonth() + 1 // getMonth() -> 0 = jan

var year = date.getFullYear()

var fulldate = AddLeadingZero(day) + "." + AddLeadingZero(month) + "." + year

System.log(fulldate)

Drink coffee.. Do stupid things faster with more energy...
Reply
0 Kudos
gbeke
Enthusiast
Enthusiast
Jump to solution

Great! Thanks a lot, Robert! Smiley Happy

Reply
0 Kudos