# How to get date now() function in Elasticsearch version 7.17.0

**URL:** <https://discuss.elastic.co/t/how-to-get-date-now-function-in-elasticsearch-version-7-17-0/370747>\
**Category:** Elastic Search\
**Created:** [November 19, 2024, 7:50am UTC](https://discuss.elastic.co/t/how-to-get-date-now-function-in-elasticsearch-version-7-17-0/370747 "2024-11-19T07:50:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shharukh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shharukh/32/139321_2.png) [@shharukh](https://discuss.elastic.co/u/shharukh)\
**Post date:** [November 19, 2024, 7:50am UTC](https://discuss.elastic.co/t/how-to-get-date-now-function-in-elasticsearch-version-7-17-0/370747/1 "2024-11-19T07:50:23Z")

</div>

```auto
// Check if 'transactionTime' and 'transactionAmount' fields exist
if (!doc.containsKey('transactionTime') || doc['transactionTime'].size() == 0 || 
    !doc.containsKey('transactionAmount') || doc['transactionAmount'].size() == 0) {
    return 0; // Return 0 if either field is missing or empty
}

// Get current date
def now = new Date();

// Extract year and month from current date
def currentYear = now.getYear();
def currentMonth = now.getMonth();

// Get transaction date
def transactionDate = new Date(doc['TransactionTransmissionDateTime_NEW_UTC'].value);

// Check if the transaction is within the current month and year
if (transactionDate.getYear() == currentYear && transactionDate.getMonth() == currentMonth) {
    // Return transaction amount if it's within the current month
    return doc['TransactionAmount'].value;
} else {
    return 0; // Return 0 if transaction is not within the current month
}

```

Example one

```auto
def month = doc['timestamp'].value.monthOfYear;

def months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 

return months[month-1];

```

I cant run any of these script in my cluster can you help me

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 17, 2024, 7:51am UTC](https://discuss.elastic.co/t/how-to-get-date-now-function-in-elasticsearch-version-7-17-0/370747/2 "2024-12-17T07:51:17Z")

</div>

Closed on December 17, 2024, 7:51am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
