Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object creation timestamp

Is there a way to retrieve the time an object was created at?

like image 810
Zach Avatar asked Mar 16 '11 15:03

Zach


People also ask

How do you initialize a timestamp?

A more general answer would be to import java. util. Date , then when you need to set a timestamp equal to the current date, simply set it equal to new Date() .

How do I do a timestamp in SQL?

MySQL TIMESTAMP() FunctionThe TIMESTAMP() function returns a datetime value based on a date or datetime value. Note: If there are specified two arguments with this function, it first adds the second argument to the first, and then returns a datetime value.


1 Answers

Not generally but you can do it for objects you create yourself via

R> df <- data.frame(a=sample(LETTERS[1:5],10,TRUE),b=runif(10))
R> attr(df, "createdAt") <- Sys.time()
R> df
   a         b
1  B 0.8437021
2  D 0.8683446
3  B 0.5194791
4  B 0.0480405
5  B 0.5604978
6  C 0.1938154
7  A 0.1451077
8  D 0.1785405
9  C 0.3937795
10 B 0.2874135
R> str(df)
'data.frame':   10 obs. of  2 variables:
 $ a: Factor w/ 4 levels "A","B","C","D": 2 4 2 2 2 3 1 4 3 2
 $ b: num  0.844 0.868 0.519 0.048 0.56 ...
 - attr(*, "createdAt")= POSIXct, format: "2011-03-16 10:42:10.137434"
R> 

and you can then write yourself some custom print() or show() functions that use the attribute. Frank Harrell's rms and its Design predecessor have done something like that for a long time.

like image 135
Dirk Eddelbuettel Avatar answered Sep 19 '22 01:09

Dirk Eddelbuettel