How to get current date in pega, YY-mm-dd format - pega

I want to get current system date in pega (Year-Month-Date)
YYYY-mm-dd
format.

Using
#(Pega-RULES:DateTime).getCurrentDateStamp()
can get current system date in YYYY-mm-dd(Year-Month-Date) format.

The below, assigned to a Text property, gives date in format yyyyMMdd:
#(Pega-RULES:DateTime).getCurrentDateStamp()
Adjusting solution given here as below, would give the desired format yyyy-MM-dd:
#FormatDateTime(#CurrentDateTime(),"yyyy-MM-dd","America/NewYork","en_US")
Tested on Pega Personal Edition 8.6.0 using Operator with Default locale "en_US" and Time zone America/New_York.

Use this function
#FormatDateTime(#CurrentDateTime(),"MM/dd/yyyy","America/NewYork","en_US")

Related

Format Date via Parameter

I have a DateTime variable (default formatting), and I would like to format it to a format to I receive from a string parameter.
I normally do something similar to: {myDate:yyyy-MM-dd}, and it works properly.
Now I have a lot of possible date formats and need to format according to the chosen one.
I have tried the following but returned garbage (ae0aor0aa):
string testFormat = "yyyy. MM. dd.";
{myDate:testFormat }
I have also tried to convert the date to string and back to date with ParseExact, but gave me an invalid date exception. NB: the date in myDate is valid, as I have checked it with the debugger.
Can you kindly advise?
Thanks to apc, it was easily solved by myDate.ToString(testFormat)

How to change UK date format in LogicApp

Im trying to convert a U.K. input date (dd-MM-yyyy) to format (yyyy-MM-dd)
I tried
"#formatDateTime('15-03-2019','yyyy-MM-dd')" ==> Error
but got error:
'In function 'convertTimeZone', the value provided
for date time string '15-03-2019' was not valid. The datetime
string must match ISO 8601 format.'
How do I go about converting this input date? The input format is (dd-MM-yyyy) and cannot be changed.
I can easily convert from (MM-dd-yyyy) as shown below, but im not able to convert from (dd-MM-yyyy)
"#formatDateTime('03-15-2019','yyyy-MM-dd')" ==> OK
Date and time functions provided by azure logic app cannot recognize the timestamp in dd-MM-yyyy format.
After my research, there is no existing function that can directly solve this problem, but you can use substring and concat to deal with this problem.
The workflow of the logic app looks like this:
The expression of the formatDataTime:
formatDateTime(concat(substring(<your-date-string>,6,4),'-',substring(<your-date-string>,3,2),'-',substring(<your-date-string>,0,2)),'yyyy-MM-dd')

Can't format the date using moment.js

Can't format the below date using moment.js, the below statement returns Invalid Date
moment('20171206T062406927Z').format('D-MMM-YYYY');
Please help me on this.
You need to tell moment which format your date string is in:
moment('20171206T062406927Z', 'YYYYMMDD[T]HHmmssSSSZ', true).format('D-MMM-YYYY');
Edit: updated as per #VincenzoC comment to ensure the timestamp is parsed in UTC
Also fix: use HH for 24-hour format (not hh), and pass a third true parameter to ensure the timestamp is parsed in strict mode.

Format hours, minutes and seconds with moment.js

I get this value from my backend service: 171054. It represents hh:mm:ss. But when I use the formatting options from the docs it gives me back 00:00:00.
Things I've tried:
moment('171054').format('hh-mm-ss')
moment('171054').format('HH-mm-ss')
moment('171054').format('HH-MM-SS')
You are confusing format option with parsing option. Since your input string is not in ISO 8601 format, you have to specify format when parsing.
Here a working example for your use case:
var mom = moment('171054', 'HHmmss');
console.log(mom.format());
console.log(mom.format('HH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
I am not sure if momentjs can read that as date since there is no identifier. I would suggest changing the value for example you have 171054, get each 2 digits since you sure that this is represent as hh:mm:ss then add identifier between then like ":" or "-" then try us momentjs formatting again.

C# format of date issue

My problem: I need to get date format as "mm/dd/yyyy"
Scenario:
I have declared DateBirth as nullable DateTime.
The value I get when I use:
AdvancedObj.DateBirth .Value.ToString()
is: "13/03/2013 00:00:00"
The value I get when I use
AdvancedObj.DateBirth .Value.ToString(CultureInfo.InvariantCulture)
is :"03/13/2013 00:00:00"//This is roughly correct but, I do not need 00:00:00
I have tried this as well, but the format is correct and value is incorrect.
AdvancedObj.DateBirth.Value.ToString("dd/mm/yyyy",CultureInfo.GetCultureInfo("en-Us"))
**"13/00/2013"**
Can anybody point me, what am I missing?
Use the right format string for months - it is MM. mm is for minutes:
AdvancedObj.DateBirth.Value.ToString("MM/dd/yyyy",CultureInfo.InvariantCulture)
Also, order them correctly as above - if you want months before days, use MM/dd/yyyy, if the other way around, dd/MM/yyyy.
I suggest you take a good long read of Custom Date and Time Format Strings on MSDN.
Month are 'M'. 'm' is for minutes.
"dd/MM/yyyy"

Resources