Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 471 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date vs DateTime

#11
There is no `Date` DataType.

However you can use `DateTime.Date` to get just the Date.

**E.G.**

DateTime date = DateTime.Now.Date;
Reply

#12
public class AsOfdates
{
public string DisplayDate { get; set; }
private DateTime TheDate;
public DateTime DateValue
{
get
{
return TheDate.Date;
}

set
{
TheDate = value;
}
}
}
Reply

#13
No there isn't. `DateTime` represents some point in time that is composed of a date and a time. However, you can retrieve the date part via the [`Date`][1] property (which is another `DateTime` with the time set to `00:00:00`).

And you can retrieve individual date properties via [`Day`][2], [`Month`][3] and [`Year`][4].

**UPDATE**: In .NET 6 the types `DateOnly` and `TimeOnly` [are introduced][5] that represent just a date or just a time.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply

#14
It seems that .NET 6 is finally introducing a date only type. It will be called `DateOnly` and there will also be a `TimeOnly` type added to the BCL in the `System` namespace.

It is already available in preview 4. Read [this blog article][1] for further details.


[1]:

[To see links please register here]

Reply

#15
As pointed by Dejan and Jonas Lomholdt,

`.Net 6` has the `DateOnly` type, it is a structure that is intended to represent only a date like a year, month, and day.

DateOnly d1 = new DateOnly(2022, 5, 16);
Console.WriteLine(d1); // 5/16/2022
Console.WriteLine(d1.Year); // 2021
Console.WriteLine(d1.Month); // 5
Console.WriteLine(d1.Day); // 16
Console.WriteLine(d1.DayOfWeek); // Monday



// Manipulation
DateOnly d2 = d1.AddMonths(3); // You can add days, months, or years. Use negative values to subtract. We are adding 3 months
Console.WriteLine(d2); // "8/16/2022" notice there is NO time

// You can use the DayNumber property to find out how many days are between two dates
int days = d2.DayNumber - d1.DayNumber;
Console.WriteLine($"There are {days} days between {d1} and {d2}"); //There are 92 days between 5/16/2022 and 8/16/2022

Full credit goes to Matt Johnson-Pint for this article:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through