Getting Time Stamp in Date

Hi All,

I am using DateTime.Parse method but getting time stamp along with date. How to remove the time stamp from date in Parse method.

@marina.dutta

strnewdate=datetime.parseExact(strdate,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantCulture).tostring(“dd/MM/yyyy”)

strnewdate is a strind datatype

at last you can mention, what ever date format you required after .tostring

cheers

Hi @marina.dutta

DateTime.ParseExact output will be of DataType System.DateTime and output will print timeStamp as it takes system format.

To not print the TimeStamp you can pass in below way:

DateTime.ParseExact(strEndDates,"dd/MM/yyyy",System.GLobalization.CultureInfo.Invariant culture).ToString("MM/dd/yyyy")

Output will be of type System.String.

Hope it helps!!

Hi @marina.dutta ,

Could you let us know what is the End Output representation you require ? Are you getting different formats/not Expected in an Excel sheet when this value is written to it ?

DateTime is a Type and it doesn’t really have a format, but we could use .ToString() on it to represent the Dates in different formats but it will be converted as String types.

Let us know what is the end output you want to perform if the .ToString("MM/dd/yyyy") is not the Expected format.

Some tutorials on DateTime and its formatting :

1 Like

Hi @marina.dutta

give format as your input dateString format like: “yyyy-MM-dd HH:mm:ss”

str_parsedDate = DateTime.ParseExact(dateString, format, System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

Hi @marina.dutta

Try this

DateTime.ParseExact(Input.ToString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

@marina.dutta

strdate=datetime.parseExact(strdate,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantCulture).tostring(“dd/MM/yyyy”)

whatever format u want you can change at last for example:dd-MM-yyyy

cheers

@supermanPunch

I have assigned one variable of type DateTime and want the Date in dd/MM/yyyy format without time stamp.

Hi @marina.dutta

in_UsageStartDate= DateTime.ParseExact(strEndDates,"dd/MM/yyyy",System.GLobalization.CultureInfo.Invariant culture).ToString("dd/MM/yyyy")

Output DataType is System.String

Regards,

@marina.dutta

Try this

@marina.dutta

In assign

strdate=DateTime.ParseExact(date,“dd/MM/yyyy”,System.GLobalization.CultureInfo.Invariant culture).ToString(“MM/dd/yyyy”)

@marina.dutta ,

As already suggested in several posts above, we could use .ToString("dd/MM/yyy") for the date to be converted to the same format. In your case, maybe the below needs to be done :

DateTime.ParseExact(strEndDates,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

The Output of the above is a String type.

But again the question arises, if the Date value is already in dd/MM/yyyy, why the need to convert it to the same format again.

Would request you to analyse and let us know if the date is being used for later part of the process and for what operation.

HI @marina.dutta

Check out this expression

Str_date = DateTime.ParseExact(Inputstring,"dd/MM/yyyy",System.GLobalization.CultureInfo.Invariant culture).ToString("MM/dd/yyyy")

Check out this Tutorial

Regards
Gokul

@supermanPunch Getting error

Getting Error

@marina.dutta ,

Mentioned already on the Conversion change in types when used .ToString()

@marina.dutta

DataType as System.DateTime

@lrtetala

I did something like this. But getting error as below screenshot

DateTime.ParseExact (strStartDate,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Sorry @marina.dutta

Please change the datatype as System.String

Hi,

hope below Screenshot help you