I use PSPad as a text editor, which allows you to press Alt + D to insert a timestamp, e.g.:
2010-07-17 23:45:44
Is there a way to do this in a Google Spreadsheet?
I use PSPad as a text editor, which allows you to press Alt + D to insert a timestamp, e.g.:
2010-07-17 23:45:44
Is there a way to do this in a Google Spreadsheet?
I use AutoHotKey to perform this function.
AutoHotKey is a Windows scripting application and language.
The code I use is below, it would be easily modifiable to insert the time and change the slashes to hyphens if that is what you prefer.
+!d:: ;Shift-Alt-D: Insert current date
SendInput %A_DD%/%A_MM%/%A_YYYY%
return
Google Sheets supports the following keyboard shortcuts:
Ctrl + Shift + : is the keystroke to insert time.
Ctrl + ; is the keystroke to insert date.
Ctrl + Alt + Shift + : is the keystroke to insert date and time.
See Keyboard accelerators, mnemonics, and shortcuts for more details.
I created a little script that converts the string literal "_now" to current datetime -
function onEdit(e) {
if (e.range.getValue() == "_now") {
e.range.setValue(new Date());
}
}
I find it pretty handy to type _now
and have it convert to current datetime value.
See https://developers.google.com/apps-script/quickstart/macros and https://developers.google.com/apps-script/understanding_events for more info on how to add this to your Google Spreadsheet
You can put in a bookmarklet with this location:
javascript:var thetime=new Date();var txtNode=document.createTextNode((thetime.getMonth()+1)+'/'+thetime.getDate()+'/'+thetime.getFullYear()+' '+thetime.getHours()+':'+thetime.getMinutes()+':'+thetime.getSeconds()); var myInputNode=document.getElementsByClassName('cell-input')[1]; if (myInputNode.hasChildNodes()) { myInputNode.replaceChild(txtNode, myInputNode.childNodes[0]); } else { myInputNode.appendChild(txtNode); }; void(0);
then edit the cell and click the bookmarklet.
The formula for current date-time is =now()
. This can be used to create a static timestamp as follows:
=NOW()
in a cell=today()
into a cell to get the current date.=now()
to get both date and time within the same cell: this is arguably the easiest way to do this without a script.
Google Sheets doesn't support it, but you can try another workaround without external apps:
(If you are on a MacOS, use Cmd instead of Ctrl for Copy/Cut/Paste
, but Ctrl + M for inserting the comment, because Cmd + M is minimizing the window.)
You can refer this tutorial, it contains video too. In the script code, change
var timestamp_format = "MM-dd-yyyy"; // Timestamp Format.
By default it only gives you date, change to below code to get time.
var timestamp_format = "MM-dd-yyyy hh:mm:ss"; // Timestamp Format.
Is this what you are looking for ? I tried it and it works perfectly.
I also created a script for this, and I wanted a format that isn't available in the default timestamps (such as in =TODAY()
or =NOW()
).
It also grabs the timezone based on the current session (which is set in the Sheet's preferences).
function _NOW(input)
{
// for formatting, see:
// https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
var timestamp_format = "yyyy-MM-dd hh:MM a"; // Timestamp Format eg: 2019-04-11 12:04 PM
var timezone = Session.getScriptTimeZone();
var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
return date;
}
Using it is easy:
=_NOW()
To clarify: I did the date formatting manually because the custom date formatting in Google Sheets is a pile of flaming trash (no way to set a custom format as the default, no way to change the order of the date/time elements without deleting everything first and adding each one part at a time).
=if(len(A2)>0;if(B2<>"";B2;now());"")
In Settings, change the circuit solution to 1, and it will work without JavaScript
tanguay, I have just tested this =IF(A2<>"",NOW(),"")
. If A2 has a value then it enters the timestamp. If A2 is empty then the timestamp is not entered in the timestamp column.