Hi,
I would like to initialize a DateTime variable. This variable should initialize with date
e.g. 25th July 2021 as 25.07.2021. I do not need the time part. Any help?
Hi,
I would like to initialize a DateTime variable. This variable should initialize with date
e.g. 25th July 2021 as 25.07.2021. I do not need the time part. Any help?
Hi! thanks for replying. I do not want to use the current date. I want to initialize with some specific date. I checked the following:
DateTime.ParseExact(“25.07.2021”,“dd.MM.yyyy”,system.Globalization.CultureInfo.CreateSpecificCulture(“de-DE”))
But it gives result like this: 07/25/2021 00:00:00
Any idea?
HI @WASEEM_KHAN
For me following code worked just fine: DateTime.ParseExact("23.09.2021","dd.MM.yyyy",System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)
I’m based in germany and also needed the german datetime format (dd.MM.yyyy) for a given string input.
Hope this helps you.
Greetings David
I am in Germany too but it also did not solve problem. I am still getting
Hi @WASEEM_KHAN
Check the below expression
DateTime.ParseExact("07/25/2021","MM/dd/yyyy",System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("MM/dd/yyyy")
Dot as Separator
DateTime.ParseExact("07/25/2021","MM/dd/yyyy",System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("MM.dd.yyyy")
Regards
Gokul
The problem is, I do not want to store my date in a string format. It should be stored in DateTime variable. You are achieving with dot separator by converting it into string and that’s the problem.
For example:
I am trying to initialize a DateTime variable with a date such as 27.07.2021 i.e. with a dot separator.
I tried with few ways but it always give me date in 07/27/2021 00:00:00. I used the following code
DateTime.ParseExact(“27.07.2021”,“dd.MM.yyyy”,System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)
or
DateTime.ParseExact(“25.07.2021”,“dd.MM.yyyy”,system.Globalization.CultureInfo.CreateSpecificCulture(“de-DE”))
Any suggestion to solve this problem?
@WASEEM_KHAN I think thats the way the datetime object from vb net works. In the documentation (https://docs.microsoft.com/de-de/dotnet/api/system.datetime?view=net-5.0#datetime-values-and-their-string-representations) is written, that the formatting is only made by using the .ToString method.
So the question would be why do you need to format the datetime object?
Hi
We can get the date format we want only if it a Datetime variable is converted to a string but
If we want only the date month and year or any format we want we can mention that in ToString(“format you want”)
Datetime output will always be of the same format with complete timestamp
And if you are passing the Datetime variable in your process it does require to format it
As it can accept the Datetime variable completely
Cheers @WASEEM_KHAN