How to get only Folder Creation Date in C# [duplicate] - c#

This question already has answers here:
Getting Date or Time only from a DateTime Object
(7 answers)
Closed 8 years ago.
I know that, Example: DateTime fileCreatedDate = File.GetCreationTime(#"C:\Example\MyTest.txt");will return the date and time of a folder creation but how do I only get the "Date"Example "2014-12-01" or "Decemeber 12,2014" of the folder creation excluding the time?

You can use the DateTime.Date property for that, i.e. fileCreatedDate.Date.

Related

Change the modified date of a file? [duplicate]

This question already has answers here:
How to edit the modified date of a folder/file?
(2 answers)
Closed 4 years ago.
In my Local folder I have a file sample.txt.
On rightclick -> properties -> Details
I can see its modified date. For example 30.10.2018 09:00.
Can I change this property trough UWP? To 20.10.2018 09:00 for example.
Yes you can do it by the following way
string path = #"c:\sample.txt";
// Take an action that will affect the write time.
File.SetLastWriteTime(path, new DateTime(1985,4,3));

How can we obtain date time format in yyyy.MM.dd [duplicate]

This question already has answers here:
C# DateTime to "YYYYMMDDHHMMSS" format
(18 answers)
Closed 4 years ago.
How can we obtain the current date in format yyyy.MM.dd in C# ASP.NET?
using DateTime.Now
Simply by using
string date = DateTime.Now.ToString("yyyy.MM.dd");
See this documentation for more info on custom date and time formats.

C# getting the date [duplicate]

This question already has answers here:
How to remove time portion of date in C# in DateTime object only?
(43 answers)
convert string to date without time
(3 answers)
Closed 5 years ago.
I'm converting a string to a date format using DateTime.Parse(). My original string consists of the date only but when i use DateTime.Parse() it adds the time to it as well giving me 01/12/2000 00:00:00. I only want the date 01/12/2000. Is there any other way to simply just get the date?
DateTime dt = DateTime.Parse("01/12/2000");
Console.WriteLine(dt.ToString("dd/MM/yyyy"));
DateTime always has a underlying Time fraction, it's just the way you define to show it that makes it look like that. So the tostring function can be used with the given formatting.
If you really want it not to have a time (and i wouldn't know why you'd want that) there are 3th party addons available.

AddYear method doesn't work as excpected [duplicate]

This question already has an answer here:
Add timespan to another timespan does not work [duplicate]
(1 answer)
Closed 8 years ago.
I need to add years to a DateTime variable, but for some reason this function doesn't affect at all..
This is my code:
DateTime dtCmp = new DateTime(calendarBirthDay.Value.Year, calendarBirthDay.Value.Month, calendarBirthDay.Value.Day);
dtCmp.AddYears(DateTime.Now.Year - calendarBirthDay.Value.Year);
I tried even something trivial likewise :
dtCmp.AddYears(1);
and this is doesn't work yet..
You need to store it back to the variable to reflect the change.
dtCmp = dtCmp.AddYears(1);
AddYears method returns a new instance of DateTime object because DateTime is a struct. You need to store returned value into itself to increase old value:
dtCmp = dtCmp.AddYears(1)

Get file modify date in C# [duplicate]

This question already has answers here:
Check last modified date of file in C#
(5 answers)
Closed 9 years ago.
How do I read the modify date of the file in C#?
I can read the creation date of the file by using the code below:
ModifyDate = File.GetCreationTime(FilePath)
File.GetLastWriteTime will do the job
I believe you're looking for GetLastWriteTime

Categories