Google Earth Engine – Create a New Column of Data with Dates for CSV Export

dategoogle-earth-enginegoogle-earth-engine-javascript-api

How could I add a "NEW" Column of Data with DATES to this SCRIPT, for export as CSV

var dataset = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
                  .filter(ee.Filter.date('2021-01-01', '2021-12-31'));
                
var precipitation = dataset.select('precipitation');

var precipitationVis = {
  min: 1.0,
  max: 200.0,
  palette: ['001137', '0aab1e', 'e7eb05', 'ff4a2d', 'e90000'],
};

Map.addLayer(precipitation, precipitationVis, 'Precipitation');


var precipitation = precipitation.map(function(image) {
    return image
        .reduceRegions({ 
      collection:Micros,
      reducer: ee.Reducer.mean(), 
      scale: 5000,
        })
      .copyProperties(image, ['system:time_start']);
});

var region = ee.FeatureCollection ('users/santiagom/Micros')

Map.addLayer(region);
print (region) 


// visualizamos
Map.centerObject(region);
Map.addLayer(region,{},'region');


// Export 
Export.table.toDrive({
  collection: precipitation.flatten()
  description: 'Lluvias',
  fileFormat: 'CSV'
}); 

Best Answer

The tricky part is when you map over the precipitation image collection. This could be one approach:

var precipitation = precipitation.map(function(image) {
  
  var result = image
        .reduceRegions({ 
      collection:Micros,
      reducer: ee.Reducer.mean(), 
      scale: 5000,
        })
  var date = image.date().format('y-MM-dd')
  
  return result.map(function(feat){ return feat.set('DATE', date)})
});

Of course you can modify the date format to match your needs