You will have to hook this into an onEdit trigger.
function timeStamp(e){
var ss= SpreadsheetApp.getActiveSpreadsheet(); //get the active spreadsheet
var sheet = ss.getActiveSheet(); //get the active sheet
var thisRow = e.range.getRow(); //identify the row number of the edited cell
var thisCol = e.range.getColumn(); //identify the column number of the edited cell
if (thisCol = 3){ //if the column number is 3 meaning C then...
if(sheet.getRange(thisRow, 4).getValue()==''){ //Check if the cell in column 4 meaning D is empty. if it is...
sheet.getRange(thisRow, 4).setValue(new Date); //Set the column 4 cell on the edited row with a new date, ie timestamp adjust your Number format.
}else{
sheet.getRange(thisRow, 5).setValue(new Date); //if the column 4 has something in it then put a new timestamp in column 5
}
}
}