C# Convert String To Datetime Without Time
Solution 1:
DateTime in .Net is always a date and a time. You can ignore the time portion if you like, but it is still there. Internally, DateTime tracks the whole number of ticks since 1/1/0001. (There are 10,000 ticks in a millisecond). So it is not possible for a DateTime to not have a time component.
For date-only data, the common convention is to use a date with the time set to midnight (00:00:00). You can get one of these from any DateTime by using its .Date property.
You'll want to be careful that once you ignore the time, that you always ignore the time. Otherwise, you may get into problems when dealing with daylight saving time issues in places like Brazil - where the time transitions from 11:59:59 PM to 1:00:00 AM. If you're not careful about how you handle your data, then date-only data stuffed in a DateTime at midnight could get misinterpreted as a local time that doesn't actually exist.
There is no built-in type for a true date without a time in the .NET Framework. However, you can find it in the LocalDate structure of the Noda Time library. You might consider using that if you have a lot of date-based business logic.
Solution 2:
myDatTime.ToString("MMM dd, yyyy"); would do the trick
Solution 3:
If I understand you .. this may help.
in c#:
if(!string.IsNullOrEmpty(yourDateTime))
{
yourDateTime.ToString("dd/MM/yyyy");
}
in sql-server:
select convert(varchar, yourDateTime ,102) as [yourDateTime]
Post a Comment for "C# Convert String To Datetime Without Time"