Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
How do I check if the file's date is today's date?
i.e. FileA20120216.csv
As you can see the date in th efile is "20120216" and i would like to compare this to todays date to see if they are the same or not.
How is this done please?
Thanks
Posted

use indexOf() or Contains method of object String.
Example
C#
if (filename.IndexOf("20120216") > 0)

or
C#
if (filename.Contains("20120216"))
 
Share this answer
 
Comments
arkiboys 16-Feb-12 3:57am    
How do I get today's date into this format i.e. YYYYmmdd ?
Thanks
Herman<T>.Instance 16-Feb-12 4:16am    
DateTime.Now.ToString("yyyyMMdd");
arkiboys 16-Feb-12 5:20am    
Thanks
u can use substring and split function to split ur file name i:e "FileA20120216.csv" into "20120216",
again splitting u can get in the date format dd-mm-yyyy from where u can compare to the current date.

use the split/substring according to the platform u are using..
because in each platform the syntax differs so..
 
Share this answer
 
Comments
arkiboys 16-Feb-12 5:19am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900