41

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?

Rubén - Volunteer Moderator -
  • 46,305
  • 18
  • 101
  • 297
Edward Tanguay
  • 3,207
  • 7
  • 29
  • 36

11 Answers11

54

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.

Danniogirl
  • 541
  • 1
  • 4
  • 2
14

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

0cd
  • 241
  • 2
  • 3
12

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
Alex
  • 22,820
  • 12
  • 83
  • 106
tobeannounced
  • 2,793
  • 2
  • 22
  • 34
7

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.

Alex
  • 22,820
  • 12
  • 83
  • 106
Ben Johnson
  • 171
  • 1
  • 1
3

The formula for current date-time is =now(). This can be used to create a static timestamp as follows:

  1. Enter =NOW() in a cell
  2. Copy this value with CtrlC
  3. Paste into the same cell with CtrlShiftV (or equivalents for "paste text only" on other platforms)
jennifer
  • 41
  • 1
1
  1. In a nearby cell, or within a frozen pane, input =today() into a cell to get the current date.
  2. Copy the cell, and then use (Paste special → Paste values only) from the edit menu, to get a static date and time, at the time that you pasted the value in the cell that you wanted the date stamp.
Alex
  • 22,820
  • 12
  • 83
  • 106
1

Google Sheets doesn't support it, but you can try another workaround without external apps:

  1. Insert a comment (Ctrl + M)
  2. Copy the TimeStamp from there (Ctrl + C or Ctrl + X)
  3. Delete the comment (Right click > Delete)
  4. Paste the TimeStamp (Ctrl + V)

(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.)

Rubén - Volunteer Moderator -
  • 46,305
  • 18
  • 101
  • 297
Lipis
  • 9,798
  • 1
  • 35
  • 43
1

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.

Arpan
  • 111
  • 2
0

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).

-2

=if(len(A2)>0;if(B2<>"";B2;now());"")

In Settings, change the circuit solution to 1, and it will work without JavaScript

jonsca
  • 1,732
  • 18
  • 23
  • 44
-2

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.