Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I name a DateTime property?

Tags:

c#

naming

If I have a class that stores a DateTime:

class LogEntry
{
    readonly DateTime dateTime;

    public LogEntry(DateTime dateTime)
    {
        this.dateTime = dateTime;
    }

    public DateTime ?????
    {
        get
        {
            return dateTime;
        }
    }
}

What should I name the DateTime property? Or should I split the property into 2 properties: 1) Date 2) Time?

edit: I was looking for a property name that provides inference that its value is both a date and a time, not a property specific to log entries (e.g., DateCreated doesn't provide any inference that it also shares the time the entry was created and vice versa).

like image 355
xofz Avatar asked Oct 05 '10 20:10

xofz


People also ask

What do you name a timestamp column?

If you use TIMESTAMP then you don't have to specify a column name and SQL Server will create a column "TimeStamp" for you. But it is recommended to use "ROWVERSION" data type and in this case you have to specify the column name.

How do you name properties in C#?

Always use camelCase with method arguments and local variables. Don't use Hungarian notation for variables. Note: Don't use abbreviations for any words and don't use underscore ( _ ) in between any name. Use PascalCase for property.

What is the namespace for DateTime in C#?

C# DateTime is a structure of value Type like int, double etc. It is available in System namespace and present in mscorlib. dll assembly. It implements interfaces like IComparable, IFormattable, IConvertible, ISerializable, IComparable, IEquatable.

Which of the following is a static property of DateTime class *?

Explanation: The DateTime class has 11 constants, no static properties or methods.


3 Answers

Assuming LogEntry is used for logging, here is how some other logging platforms do it:

log4net calls it TimeStamp in the LoggingEvent class.

NLog calls it TimeStamp in the LogEventInfo class.

Enterprise Library calls it TimeStamp in the LogEntry class.

Microsoft calls it DateTime in the TraceEventCache class.
(TraceEventCache is passed into TraceListener Trace* calls. DateTime is the time at which the logging message was generated.)

like image 133
wageoghe Avatar answered Nov 15 '22 16:11

wageoghe


LogDate
CreatedDate
EntryDate
StarDate // **

Pick a name that you feel describes the property best. And, no, do not split the property.

like image 29
Anthony Pegram Avatar answered Nov 15 '22 15:11

Anthony Pegram


TimeStamp maybe?

like image 28
SwDevMan81 Avatar answered Nov 15 '22 15:11

SwDevMan81