Formatting date-based strings

(imported topic written by atlauren)

Hi all,

What is the most efficient way to obtain a formatted date string within? Occasionally in directives to executables, I’d like to specify names of output logs and such based on the current date.

In UNIX I’d embed something like: date +%Y%m%d

In PowerShell: (get-date -Uformat “%Y%m%d”)

This gets the results I want in BigFix: (current year as string) & (current month as two digits as string) & (current day_of_month as two digits as string)

…but surely there’s a more efficient construct?

Thanks,

Andrew

(imported comment written by Lee Wei)

Hello Andrew,

You are not missing anything, there are no formatting templates.

Here are 2 code fragments that I keep around - one for date and one for date/time - that I have to format to my liking.

Date format:

(year of it as string & “/” & month of it as two digits & “/” & day_of_month of it as two digits) of current date

2013/09/17

Time format:

((year of it as string & “/” & month of it as two digits & “/” & day_of_month of it as two digits) of date(local time zone) of it & " "& (two digit hour of it as string & “:” & two digit minute of it as string & “:” & two digit second of it as string) of time (local time zone) of it) of now

2013/09/17 12:35:11

Lee Wei

(imported comment written by VipulSri)

Thanks Lee. I too have a format which I like.

Date Format:

(day_of_month of date (local time zone) of now as two digits as string) & “-” & ((month of date (local time zone) of now) as string) & “-” & (year of date(local time zone) of now as string)

Vipul

(imported comment written by jgstew)

Here are 2 different ways to get the same date format of “now”:

http://bigfix.me/relevance/details/2996999

http://bigfix.me/relevance/details/2997194