__DATE__ equivalent
-
Thursday, November 09, 2006 5:19 PM
I'm new to C# coming from a C background. I would simply like access to the build date of my application. In C, I could do this using the __DATE__ macro. How would I do this in Visual C#?
TIA
JeffM
All Replies
-
Thursday, November 09, 2006 7:22 PM
Use DateTime structure in C#!
See MSDN for help and more details! its really very simple to use!
Best Regards,
-
Thursday, November 09, 2006 10:20 PM
I guess there is no way to do that. C# does not allow defines with values. It allows only "is defined" or "is not defined".
--
SvenC -
Thursday, November 09, 2006 11:09 PMModerator
hi,
i don't know c and i don't know if you can do that useing System.Refliction or not but you can get the creationdate from System.IO
class Program {
static void Main(string[] args)
{ string strpath = System.Reflection.Assembly.GetExecutingAssembly().Location;
System.IO.FileInfo fi = new System.IO.FileInfo(strpath);
Console.WriteLine(fi.CreationTime);
}
}
it will not give you the build date but it will give you the creation date on the client machine
hope this helps
-
Friday, November 10, 2006 5:37 AM
__DATE__ is a define which is evaluated at compile time, so you can have the build date available as string - maybe for diagnostics or an about dialog or whatever.
--
SvenC -
Friday, November 10, 2006 5:22 PM
If you use "1.0.*.*" as the assemblyVersion in your AssemblyInfo.cs file, then the build (3rd) number will give you the date, while the revision (4th) number will be the time. I forget the exact format, but I think it's something like Build = days since 1/1/1970, and Revision=(seconds since 12mid)/2
-
Friday, November 10, 2006 5:39 PM
OK, I was close... It is "days since 1/1/2000" -- this code will work:
Assembly assem = Assembly.GetExecutingAssembly();
Version vers = assem.GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2);
Console.WriteLine(vers.ToString());
Console.WriteLine(buildDate.ToString());

