I have a basic date format question, i have a todays date which returns the output as 11/26/2021 08:01:20 storing this result in a String variable say Date1
I want to convert this date format to 26/11/2021 excluding the time format and store it in a datetime variable say Date2
Kindly share a sample code for the above query
Want to learn more about date share any link if any.
Actually, create a variable called var_Date and set the datatype as DateTime, and also create another variable var_Str and datatype would be string only.
Then,
Store the incoming datetime value in var_Date, and assign the value for var_Str as var_Str = var_Date.ToString(“dd/mm/yyyy”).
Print the var_Str value in the output panel, and you would achieve the output.
Ok, is it mandatory that the end result should be stored in String ?
i tried to store the result in a datetime variable using assign activity - CDate(var_Str) i am getting the result along with timestamp, and how to remove this timestamp. Suggestions needed.
Please find below XAML file, this is my re usable workflow. This workflow will converts any of your date format into required format. XAML 11_ConvertDateTimeToRequiredFormat.zip (3.4 KB)
I have also explained about this workflow in my YouTube video. attaching the below link, do check it out Youtube URL : Convert any date To specific Date
Hi i find your code intresting can you explain your code a little bit?
specially the part on the “else”.
note:seen the video but still confused on the else assign parts
I had requirement where, There could be Date provided by user and if there no Date provided by them, I needed to consider the Today’s Date.
So my workflow has a logic,
It checks if there is any provided by you. If it is empty, then It will consider the Today’s date (this is the THEN Part of IF condition)
If it contains the any date, then The ELSE part come into picture. Here, instead of Today’s date, it will convert the date provided as input
Hi thanks ,
i get that part
sorry i didint explain my question better
i mean this part :
DateTime.ParseExact(in_DateTimeValue, in_OriginalFormat, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString(in_RequiredFormat)
because last time i try this i cant use string as in_date value ,
can you elaborate?
Hi,
With regards to above question, there is 2 thing
your input format is of “MM/dd/yyyy HH:mm:ss” but your trying to parse the format as “dd/MM/yyyy”. This is why you are receiving error
The difference between your logic and mine is, I used a Array for string to format date.
The reason i did this because, i had multiple format of input date and i required only 1 standard output date. If you want to use my workflow, then Please check, if the in argument, in_OriginalFormat [] is having the format “MM/dd/yyyy HH:mm:ss”.
If Not, then Please Add.
(Since its array, i have added few of format, and if any new format is our requirement, we need to append the argument value as per our requirement.)
example :
in_OriginalFormat = {“MM/dd/yyy”,“MM/dd/yyyy HH:mm:ss”}
Main Logic of my workflow:
DateTime.ParseExact(Date1, in_OriginalFormat, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString(in_RequiredFormat)
here, in_RequiredFormat is the format which you want as output
Fix on your logic : considering your output format is “dd/MM/yyyy”
DateTime.ParseExact(Date1, “MM/dd/yyyy HH:mm:ss”, CultureInfo.InvariantCulture,DateTimeStyles.None).ToString(“dd/MM/yyyy”)