@EVAL return date('Y-m-d H:i:s');
@EVAL return time();
This question has been answered by BobRay. See the first response.
$tv->set('default_text', time(); $tv->save();
if ($mode != modSystemEvent::MODE_NEW) { return ''; }
$tv->set('default_text', strftime("%Y-%m-%d %H:%M",time());
If you use @EVAL, you'll get a new date every time the default value is used.
I think it would take a plugin to do what you want, but a very simple one -- connected to OnTVFormSave.
This would put a unix timestamp for the current date/time in the TV:
$tv->set('default_text', time(); $tv->save();
It won't change when a value is set for a resource, but it will change if you edit and save the TV itself. To prevent that, put this at the top:
if ($mode != modSystemEvent::MODE_NEW) { return ''; }
If you need a human-readable date/time in the default value, use something like this:
$tv->set('default_text', strftime("%Y-%m-%d %H:%M",time());
I can't answer your question about @eval but if you want a date tv to show the current date by default all you have to do is go to the tv's input options and type the word "today", no quotes, in the default value text box.
You can format the output in the output tab and put in whatever you want for your a typical date format.
i.e. %a %b %e, %Y for Sun Nov 18, 2012
Good question I actually didn't find that anywhere was just doing some trial and error testing and stumbled on it. Was an AHA moment! Went out and celebrated with an ice cream[ed. note: exside last edited this post 11 years, 1 month ago.]
Good to know there's other short codes too.
if anybody knows 1. where to find them in the code (I tried everywhere I could, but couldn't find any hardcoded strings like "today" and "now" in files that have to do with dateTV types)