The output I required
2023/07/14
Thanks in advance
The out put i am getting
“07/14/2023 00:00:00”
The output I required
2023/07/14
Hi,
Assign:
Left side: dateVariable
Right side: dateTimeVariable.ToString(“yyyy-MM-dd”)
Can you try this syntax,Hope it helps
@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”
Try this
dateString = “2023-07-17”
Date=DateTime.Parse(dateString).AddDays(-3).ToString(“yyyy/MM/dd”)
I hope it helps!!
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
Could you please change the dateNow variable type to string
Remove the Cdate in the value to save field.
Hope it helps!!
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.
After that take the another variable of Datetime format and then give like this
DateFormat variable in Datetime datatype.
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!!
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
Hi,
Assign:
Left side: dateVariable data type is date
Right side: dateTimeVariable.ToString(“yyyy-MM-dd”)
Try this