Questions tagged [dateonly]

15 questions
54
votes
3 answers

DateTime.Now equivalent for TimeOnly and DateOnly?

.NET 6 / C# 10 introduced TimeOnly and DateOnly structs, to represent only a time and only a date respectively. The good old DateTime struct always had a Now static property which would give you the current date and time. I was expecting both…
Arad Alvand
  • 8,607
  • 10
  • 51
  • 71
30
votes
5 answers

Subtract DateOnly in C#

In C# I can't use subtraction with DateOnly variables, unlike DateTime. Is there any explanation? var a = new DateTime(2000, 01, 01); var b = new DateTime(1999, 01, 01); //var c = a.Subtract(b); var c = a - b; var d = new DateOnly(2000,…
Silenus
  • 667
  • 1
  • 7
  • 16
7
votes
1 answer

Does AutoFixture support `DateOnly` for .NET6?

I'm getting exception on constructing DateOnly variables/fields with AutoFixture. (constructing of TimeOnly works fine) AutoFixture.ObjectCreationExceptionWithPath : AutoFixture was unable to create an instance from System.DateOnly because creation…
Evgeny
  • 791
  • 7
  • 15
3
votes
4 answers

How to convert System.DateTime? to System.DateOnly?

How can I convert nullable DateTime to nullable DateOnly? So DateTime? to DateOnly? The error says: Error CS0029 Cannot implicitly convert type 'System.DateOnly?' to 'System.DateTime?' I can convert from DateTime to DateOnly by doing: DateOnly…
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
2
votes
1 answer

DateOnly & TimeOnly Web API .NET 6

I'm having difficulties on sending the value of DateOnly & TimeOnly in .Net 6 to database. I have read multiple answers here on this issue, and have tried it all but its still showing error 400 heres the converter I made public class…
S S
  • 19
  • 3
2
votes
3 answers

Compare DateOnly values with DateTime. Shouldn't it be possible?

Using .Net 6 and VS2022 , consider this code: DateOnly dateOnly= new DateOnly(2022,12,24); DateTime dateTime = DateTime.Now; if (dateTime > dateOnly) { } It will result in this error: Operator '>'…
MD Zand
  • 2,366
  • 3
  • 14
  • 25
1
vote
1 answer

How to serialize DateOnly using refit.?

I'm searching for this since 3-4 days I've almost got the answer but still I can't implement in my code. Actually I never understand or can't work by seeing the documentation. :/ And I need another suggestion as well I'm using date only because I…
0
votes
2 answers

How to specify a custom DateOnly format with CsvReader?

I need to read a CSV file using CsvReader, however I have a custom date format (yyyyMMdd) which by default can't be converted to DateOnly. How can I specify this custom date format? Is that may possible using some annotation? This is the code I…
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
0
votes
0 answers

Using SqlDataRecord with DateOnly

I've got a SQL Server user defined table with a date field. I represent that locally using a DateOnly. I represent the rows locally using SqlDataRecord. But it doesn't appear to support DateOnly. Is there a sensible way of using SqlDataRecord to…
Julian Birch
  • 2,605
  • 1
  • 21
  • 36
0
votes
0 answers

ASP.NET Core model binding fails for DateTime or DateOnly types

In my ASP.NET Core 6.0 api project, I have this endpoint in the controller: [HttpGet("Customers/{DateOfBirth}")] Task GetCustomers([FromRoute] DateTime? dateOfBirth, CancellationToken token){....} I'm calling that endpoint with a…
Stack Undefined
  • 1,050
  • 1
  • 14
  • 23
0
votes
0 answers

How DataSourceLoadOptions work with DateOnly in C#

I do have a List where MyObject contains a property which is DateOnly. At the end of my service I want to apply some DevExtreme.AspNet.Mvc.DataSourceLoadOptions on the List: return DataSourceLoader.Load(myList, loadOptions); The…
Stix
  • 455
  • 5
  • 16
0
votes
0 answers

DateOnly in model C# class mapping to Date in SQL Server with EntityFrameworkCore

I have been scaffolded existing DB from SQL Server to my project with EntityFrameworkCore and it created models with public DateTime Birthday { get; set; } Now I have to change DateTime to DateOnly This exception is thrown when I'm trying to read…
0
votes
1 answer

DateOnly C# doesn't bind in razor page

I'm using DateOnly property. When I bind it in input it doesn't bind in default date time picker while I'm in my update view. Though When I inspect it the "input" element has value but it doesn't bind in my calender. Is this due to new DateOnly…
0
votes
2 answers

Value from HTML date picker is not interpreted in ASP.NET Core MVC controller

Value from HTML date picker is not interpreted in ASP.NET Core MVC controller Context ASP.NET Core MVC web application targeting .NET 6.0 Entity Framework Core 6.0.6 SQL Server Local DB The forms contain HTML date picker. Goal Being able to…
0
votes
2 answers

How can I properly filter nullable DateOnly?

I have successfully configured a DateOnly property on my EF 6 entity as below Everything is working great, except for the fact that the property is nullable. The issue occurs when I try to filter entities where Prperty1 < [some-date], in that EF…
Bassie
  • 9,529
  • 8
  • 68
  • 159