_TIMESTAMP_ and __TIME__ equivalent in C#

E

Eitan

Hello,

I would like to display a timestamp of when the application was compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
N

Nicholas Paldino [.NET/C# MVP]

EitanB,

No, there isn't. The best you could do is get the current assembly and
get the created date, but you can't guarantee that date will be accurate.
 
E

Eitan

Hi,

What would be the way to get the current assembly and the created date?

Thanks
EitanB

Nicholas Paldino said:
EitanB,

No, there isn't. The best you could do is get the current assembly and
get the created date, but you can't guarantee that date will be accurate.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hello,

I would like to display a timestamp of when the application was compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
N

Nicholas Paldino [.NET/C# MVP]

Eitan,

Call the static GetExecutingAssembly method on the Assembly class. From
there, look at the Location or CodeBase properties (depending on where the
assembly was loaded from) which will give you a path. With that path, you
can use a FileInfo instance (or the static methods on the File class) to get
the created date of the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hi,

What would be the way to get the current assembly and the created date?

Thanks
EitanB

Nicholas Paldino said:
EitanB,

No, there isn't. The best you could do is get the current assembly
and
get the created date, but you can't guarantee that date will be accurate.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hello,

I would like to display a timestamp of when the application was
compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
P

Peter Bromberg [C# MVP]

Nick,
Why would the date not be accurate? If I do this:

static void Main(string[] args)
{
Assembly assy = Assembly.GetExecutingAssembly();
string path = assy.Location;
DateTime dt = File.GetCreationTime(path);
Console.WriteLine(dt);
Console.ReadLine();
}
}

-- and I do a Rebuild, the Creation date stays the same. Enlighten us!
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


Nicholas Paldino said:
EitanB,

No, there isn't. The best you could do is get the current assembly and
get the created date, but you can't guarantee that date will be accurate.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hello,

I would like to display a timestamp of when the application was compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
E

Eitan

Nicholas,

Thanks!!

Used LastWriteTime, it gave me the time of the compile (I think....)

Eitan

Nicholas Paldino said:
Eitan,

Call the static GetExecutingAssembly method on the Assembly class. From
there, look at the Location or CodeBase properties (depending on where the
assembly was loaded from) which will give you a path. With that path, you
can use a FileInfo instance (or the static methods on the File class) to get
the created date of the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hi,

What would be the way to get the current assembly and the created date?

Thanks
EitanB

Nicholas Paldino said:
EitanB,

No, there isn't. The best you could do is get the current assembly
and
get the created date, but you can't guarantee that date will be accurate.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I would like to display a timestamp of when the application was
compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

Creation time is not passed along when the assembly came from an
external website. If the assembly was downloaded from the internet, then
the location will point the location that the file was shadow-copied to, and
the creation time will be the time that it was downloaded, not the time that
the assembly was compiled.

An edge case, yes, but completely possible.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Bromberg said:
Nick,
Why would the date not be accurate? If I do this:

static void Main(string[] args)
{
Assembly assy = Assembly.GetExecutingAssembly();
string path = assy.Location;
DateTime dt = File.GetCreationTime(path);
Console.WriteLine(dt);
Console.ReadLine();
}
}

-- and I do a Rebuild, the Creation date stays the same. Enlighten us!
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


Nicholas Paldino said:
EitanB,

No, there isn't. The best you could do is get the current assembly
and
get the created date, but you can't guarantee that date will be accurate.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eitan said:
Hello,

I would like to display a timestamp of when the application was
compiled.
In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

Thanks,
EitanB
 
B

Ben Voigt [C++ MVP]

Eitan said:
Hello,

I would like to display a timestamp of when the application was
compiled. In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

[assembly: AssemblyVersion("1.1.*")]
When specifying a version, you have to at least specify major. If you
specify major and minor, you can specify an asterisk (*) for build. This
will cause build to be equal to the number of days since January 1, 2000
local time, and for revision to be equal to the number of seconds since
midnight local time, divided by 2.
 
B

Ben Voigt [C++ MVP]

Ben said:
Eitan said:
Hello,

I would like to display a timestamp of when the application was
compiled. In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

[assembly: AssemblyVersion("1.1.*")]
When specifying a version, you have to at least specify major. If you
specify major and minor, you can specify an asterisk (*) for build.
This will cause build to be equal to the number of days since January
1, 2000 local time, and for revision to be equal to the number of
seconds since midnight local time, divided by 2.

BTW, it's a little confusing to find the version at runtime, you need
Assembly.GetName().Version
 
N

Nicholas Paldino [.NET/C# MVP]

While this will work, this is purely an implementation detail. The OP
should be aware of this, and have a backup in the event his app stops
working because that detail changes.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ben Voigt said:
Ben said:
Eitan said:
Hello,

I would like to display a timestamp of when the application was
compiled. In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

[assembly: AssemblyVersion("1.1.*")]
When specifying a version, you have to at least specify major. If you
specify major and minor, you can specify an asterisk (*) for build.
This will cause build to be equal to the number of days since January
1, 2000 local time, and for revision to be equal to the number of
seconds since midnight local time, divided by 2.

BTW, it's a little confusing to find the version at runtime, you need
Assembly.GetName().Version
 
B

Ben Voigt [C++ MVP]

Nicholas said:
While this will work, this is purely an implementation detail. The OP
should be aware of this, and have a backup in the event his
app stops working because that detail changes.

It's part of the public contract for AssemblyVersionAttribute.

http://msdn2.microsoft.com/en-us/li...ersionattribute.assemblyversionattribute.aspx

However another page says the revision is "random".

http://msdn2.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx
Ben Voigt said:
Ben said:
Eitan wrote:
Hello,

I would like to display a timestamp of when the application was
compiled. In C++ I used the _TIMESTAMP_ and __TIME__ etc.

Do we have anything equivalent in C# and .NET?

[assembly: AssemblyVersion("1.1.*")]
When specifying a version, you have to at least specify major. If
you specify major and minor, you can specify an asterisk (*) for
build. This will cause build to be equal to the number of days
since January 1, 2000 local time, and for revision to be equal to
the number of seconds since midnight local time, divided by 2.

BTW, it's a little confusing to find the version at runtime, you need
Assembly.GetName().Version
Thanks,
EitanB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top