All Questions
114 questions
27
votes
2
answers
2k
views
Why is the month abbreviated differently when the date format includes a slot for days as opposed to when it doesn’t?
When running a .NET 8 console application, why does MMM show "June" instead of "Jun" when its part of a date format (e.g. .ToString("dd-MMM-yy")) but "Jun" (e.g....
1
vote
0
answers
104
views
How to use data attribute to format a DateTimeOffset property in C#?
I have a C# class which is used as a API json response. I have some properties defined as DateTimeOffset.
public DateTimeOffset Time1 { get; set; }
public DateTimeOffset Time2 { get; set; }
The ...
0
votes
1
answer
100
views
Why is there a difference in formatting a DateTime depending on the incoming DateTime-Format?
I have code which parses a DateTime and formats it like this:
DateTime.Parse(DateTimeValueXY, CultureInfo.InvariantCulture).ToString("dd/MM/yyyy hh:mm:ss tt")
In one case I get the error
...
0
votes
0
answers
221
views
Getting Error "String was not recognized as a valid DateTime" while formatting date string
I am really confused and probably I am completely blind currently.
I get a DateTime from an external source like this and as string:
"9/29/2022 5:32:36 AM"
Whend I parse and format the ...
0
votes
1
answer
232
views
C# How to convert the date that have been retrieve from DB and Where should I write?
In this task, I am trying to write a method that filters according to the date entered by the user. But I couldn't figure out where and how to write the format changing code.
I have a DateTime object ...
0
votes
1
answer
4k
views
Dapper return data type DATE with time
I have problem. I have MySQL database and I use DATE type for my date column. I want to save date without time only.
In database date is saved like this 06/02/1999 for example.
But when I try to take ...
-1
votes
2
answers
70
views
DateTime formatting option
What is the appropriate DateTime formatting option in NET/C# to achieve more efficiently the same as this:
DateTimeOffset dt = <some_date_with_time>;
string dtStr = $"'{dt.Year}/{dt.Month}/{...
-1
votes
1
answer
351
views
Datetime formats are inconsistent between DateTime.ToString and DateTime.ParseExact
this is very curious. When I run, for example,
DateTime.Now.ToString("dd/MM/yyyy")
Result is
"22-02-2022"
Notice that I requested a slash separator, not hyphen separator. However,...
-3
votes
1
answer
168
views
How can I parse a datetime with a nonstandard format (yyyyMMdd:Hmm)?
We have an integration partner who insists on sending us datetimes as strings in the format yyyyMMdd:Hmm, e.g., "20211029:102". Note that the hour does not have a leading zero.
I tried to ...
0
votes
1
answer
52
views
How Can I get Today's date with UFTC stamp in c#?
Is there an inbuild DateTime functionality that could give me a string format of today's date as 2020-12-22T13:36:45 Etc/UTC (+00)
I can think of these ways:
var date = DateTime.Now;
var result = date....
-1
votes
1
answer
83
views
converting current datetime to different format
How can I convert the DateTime.now() to the following format in C#.
2020-05-28T00:00:02Z
Any help will be highly appreciated.
0
votes
1
answer
1k
views
How do I format Datetime to remove seconds in model?
I'm using Datetime and would like seconds removed from what is stored in my database. In one of my old projects, I formatted the date part of Datetime like this:
[DataType(DataType.DateTime)]
[...
-1
votes
1
answer
141
views
DateTime.Now.ToString("M/d/yyyy HHmmss") returns month only in deployed location
Creating a new folder
string newFolder = Globals.applicationPath + @"BatchHistory\Batch" + DateTime.Now.ToString("M/d/yyyy HHmmss") + @"\";
In the dev PC everything works as expected folder is named: ...
0
votes
1
answer
9k
views
C#. String was not recognized as a valid DateTime
I have a string:
string date = "2019-06-06T14:31:55.7316366+03:00";
and I'm trying to map it to DateTime:
var formattedDate = DateTime.ParseExact(date, "dd/MM/yyyy", null)
But I have an exception: "...
0
votes
1
answer
797
views
How to format DateTime / TimeSpan from String in C#
I receive a string in this format "7:00 am - 11:00 pm" representing start and end time. The string will always have two times. Now I need to format that to today's date & time so in above case it'...