Page 1 of 1

Date Countdown In Label

Posted: Mon Mar 30, 2015 8:41 pm
by Jeremiah Olugbola

Hi I'm trying to create a text countdown in a label showing the user that they have
"x amount of days" left till the date they specified when they registered as a user to the app. I have a column in the user collection saving the date the user selected I am wondering how I can display this date minus the current date.

I have tried to implement a JavaScript event on page show however I am not having much luck. How can I create a new variable from the user collection in my database?


Date Countdown In Label

Posted: Tue Mar 31, 2015 1:39 am
by Yurii Orishchuk

Hi Jeremiah,

You can do it with JS code. Here is an example of code:

pre

//You should use here your stored date.
var dateBefore = new Date("2014-04-15 00:00:00.000");
var dateNow = new Date();
var difference = dateNow.getTime() - dateBefore.getTime();
var differenceDays = difference / (1000 * 60 * 60 * 24);
var daysRound = Math.floor(differenceDays);

alert(daysRound + " amound of days");

/pre

Regards.


Date Countdown In Label

Posted: Tue Mar 31, 2015 2:01 am
by Jeremiah Olugbola

I had something similar with my JS code, what Im after is how I can get the dateBefore variable to be pulled up from a date in my user collection.
I have a date column in my user collection I am trying to use that date as the dateBefore value. How would I do that?


Date Countdown In Label

Posted: Thu Apr 02, 2015 12:35 am
by Yurii Orishchuk

Hi Jeremiah,

It's very depends on your implementation.

But if you actually have some read user service, you can do following in the "Success" mapping:

  1. Link date field response parameter to some label component on the page.

  2. Click on "JS" for this link.

  3. Populate it with following JS code:

    pre

    var dateString = value;

    var dateBefore = new Date(dateString);
    var dateNow = new Date();
    var difference = dateNow.getTime() - dateBefore.getTime();
    var differenceDays = difference / (1000 * 60 * 60 * 24);
    var daysRound = Math.floor(differenceDays);
    alert(daysRound + " amound of days");

    /pre

    Regards