Convert DateTime to string and remove unwanted time?


#1

Hey,

I have a variable A=11/20/2018 00:00:00, type of it is DateTime

How to get a string as 20.11.18? Thanks


#2

Hi.

Using vb.net you can place the format next to the .ToString
For example:

variable.ToString("dd.MM.yy")

…assuming the variable is of a DateTime type, which if it is not, then you would need to convert it first.

Regards.


#3

Use

Convert.ToDateTime(A).ToString(“dd.MM.yy”)

It Will Work Fine


#4

Hi @ClaytonM @Himanshu.joshi

both commands are not working with me. I shared the workflow and made an annotation where the conversion is required. Can you please check it?
Main.xaml (8.6 KB)


#5

It worked for me. See screenshot highlighted in yellow…

Thanks.


#6

Main (6).xaml (7.2 KB)

Here is The Workflow Which Works fine.


#7

That is really nice but I dont only want to display it using message box. I wanna save the Date 20.11.18 as string in variable. How? Because I keep becoming error while assigning it to a new string variable. Thanks


#8

The Varialbe i which you assign will be string type

String var=Convert.ToDateTime(CD).ToString(“dd.MM.yy”)


#9

Hi
This is answer for your question

A.ToString(“dd.MM.yy”)

try various format, follow below link
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Thanks