Convert Datetime to Date

The output I required

2023/07/14

Thanks in advance

@ManjunathReddy

Now.Tostring(“yyyy-MM-dd”)

Hi @ManjunathReddy

Try this

Now.AddDays(-3).ToString("yyyy/MM/dd")

I hope it helps!!

Hi @ManjunathReddy

dateNow.ToString(“yyyy/MM/dd”)

Hope it helps!

The out put i am getting

“07/14/2023 00:00:00”

The output I required

2023/07/14

@vrdabberu @pravallikapaluri @lrtetala

@ManjunathReddy

Hi,

Assign:
Left side: dateVariable
Right side: dateTimeVariable.ToString(“yyyy-MM-dd”)

Can you try this syntax,Hope it helps

@ManjunathReddy

Try this

@ManjunathReddy
DateTime currentDate = DateTime.Now;
DateTime threeDaysBefore = currentDate.AddDays(-3);

string dateOutput = threeDaysBefore.ToString(“yyyy/MM/dd”);
Console.WriteLine(dateOutput); // Output: The date three days before the current date in the format “yyyy/MM/dd”

@ManjunathReddy

I have got the output please check

Regards

@ManjunathReddy

Try this

dateString = “2023-07-17”
Date=DateTime.Parse(dateString).AddDays(-3).ToString(“yyyy/MM/dd”)

I hope it helps!!

@ManjunathReddy

Try this if you required the date for 3days before

Regards

@ManjunathReddy

Datetime variable will be in the format of date and time together if you need only date then you need to use .ToSstring and convert it…as you are doing cdate which is conversion to date it gets stored as a datetime variable only which will append a default time to it

So instead change the variable type to string and store it Now.AddDays(-2).ToString("yyyy/MM/dd") the output of this would be a string and in the expected format

Cheers

Hi @ManjunathReddy

Could you please change the dateNow variable type to string

  • Assign → dateNow = (Now.Date.AddDays(-3).ToString(“yyyy-MM-dd”))

Remove the Cdate in the value to save field.

Hope it helps!!

Hi @ManjunathReddy

Try this:

Hello @ManjunathReddy, Your syntax is good. Just remove the Cdate and DateNow Variable should be in String type.

Datenow=Datetime.now.addDays(-3).ToString("yyyy/MM/dd")   ------> Datenow is String variable type

dateNow Variable is string value is “now.Date.AddDays(-3).ToString(“yyyy-MM-dd”)”

Output : 2023-07-14

dateNow Variable is string value is “CDate(now.Date.AddDays(-3).ToString(“yyyy-MM-dd”)).ToShortDateString”

Output : 07/14/2023

I have to enter the in this format " 2023-07-14 " & Should be Date Format

Thank you all.

@mkankatala @Anil_G @Gokul_Jayakumar @pravallikapaluri

After that take the another variable of Datetime format and then give like this
DateFormat variable in Datetime datatype.

  • Assign → DateFormat = CDate(“dateNow”)

If you change the format like this you will get the time value like this 07/14/2023 00:00:00

better to take the value in string format then you will get the required date format.

Hope you understand!!

@ManjunathReddy

If in date format you cant get it as required…because date format takes the default system date format or the cultural format and also as explained earlier …it would contain time as well by default

Can you please explain your requirement of why you need date variable in a specific format?

If using for any comparision the. Other date variable also wont be in the format you are expecting

Cheers

@ManjunathReddy

Try this

Regards

@ManjunathReddy

Hi,

Assign:
Left side: dateVariable data type is date
Right side: dateTimeVariable.ToString(“yyyy-MM-dd”)

Try this