Date functionality

Hi Team,

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

  1. 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
  2. Want to learn more about date share any link if any.

Thanks
Robotics

Hi @Robotics
Var_date=Datetime.Parse(input) \Var_date is type of datetime variable
var_str=Var_date.ToString(“dd/mm/yyyy”)

Thanks,

@Robotics

check below for your reference

Reference for Date

Hope this may help you

Thanks

image
image

Reulst
image

reference : Robinnavinraj S

Best Regards
ahmad

var_str=Var_date.ToString(“dd/mm/yyyy”) - here i want to store the result in a datetime variable instead of string(var_str). How to change this ?

Hi @Robotics,

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.

Thanks,
@Robinnavinraj_S

You are storing the end result Date2 in a string right, but i want it in a datetime variable without timestamp as 26/11/21

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.

Hi @Robotics

Please refer to the Xaml file provided , & test it out .

Hope this solves your issue

Thanks,
test2.xaml (4.8 KB)

HI Robin ,
i still find this question tricky and the xamlu share have missing activites can u share the whole folder?
thanks

Hey @Robotics ,

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

In case of any issue, let me know

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

thanks
regards

Hi @Ahmad_Rais ,

Sure, Let me explain you the ELSE part.

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?

thanks

Sure,

Could you please share me what value your trying to pass in the argument in_DateTimeValue ?

I mean the format of date , is it lets say, 27/11/2021 08:56:00 or something else?

i was using a data type string with this code , date1 is a string with this value : 11/26/2021 08:01:20

DateTime.ParseExact(Date1, “dd/MM/yyyy”, CultureInfo.InvariantCulture)
can you please tell me how its diffrent from yours?
image

Hi,
With regards to above question, there is 2 thing

  1. 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

  2. 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”)

4 Likes

Hi thanks for reply,
i will review my code later

thanks

1 Like

@Ahmad_Rais ,

Sure, let me know if you need any help