title: Getting Date Time value in Firebase Functions
body: <p>I'm trying to get the date time value of the server and I've implemented the code below. However, the return value of the time is sometimes null and sometimes not working as expected.</p>
  
  <p>The main reason for the https request code is to check if the code has already run today so that it does not duplicate its action. </p>
  
  <pre><code>export const helloWorld = functions.https.onRequest((request, response) =&gt; {
      response.send("Hello from Firebase!")
      const database = ref.child('Admins/currentDate')
      const timeStamp = admin.database.ServerValue.TIMESTAMP
      const currentTime = new Date(timeStamp)
      const currentDate = currentTime.getDate().toString
      const currentMonth = currentTime.getMonth().toString
      const currentYear = currentTime.getFullYear().toString
      const dateFormat = currentDate + " " + currentMonth + " " + currentYear
      database.once('value').then(function (snapshot) {
          snapshot.forEach(function (data) {
              const appTime = data.val().currentTime
              if(appTime === dateFormat){
                  console.log("Points already added today." + dateFormat)
              }
              else{
                  console.log("All points successfully updated." + dateFormat)
                  data.ref.update({currentTime : dateFormat})
                  .catch(console.error)
                  udpateAllPoints()
              }
          })
      }).catch(console.error)
  })
  </code></pre>
  
  <p>NOTE: <code>updateAllPoints()</code> is used to increase all the user points by 10% [This code works as expected]</p>
  
  <pre><code>function udpateAllPoints(){
      const database = ref.child('Users')
      database.once('value').then( function (snapshot){
          snapshot.forEach(function (data){
              const points = data.val().points
              const updatedPoints = updatePoints(points)
              const userId = data.key
              data.ref.update({ points : updatedPoints})
              .catch(console.error)
              console.log("This User "+ userId +"has "+points+ "points. \n")
          })
  
      }).catch(console.error)
  
  }
  </code></pre>
  
  <p>Current Sample Output of dateFormat are something like these:  </p>
  
  <ol>
  <li><p>When the above code is run   </p>
  
  <pre><code>function toString() { [native code] } function toString() { [native code] } function toString() { [native code] }   
  </code></pre></li>
  <li><p>When removed toString   </p>
  
  <pre><code>function { [native code] } function  { [native code] } function  { [native code] }   
  </code></pre></li>
  <li><p>When use Date.Now() or new Date() instead of new Date(timeStamp)  </p>
  
  <pre><code>NaN NaN NaN   
  </code></pre></li>
  </ol>