JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

Hi

I'd like to "get" a date i've set previously in my data base (I can do this bit with the read service no drama), add X days and display it in the UI.

I cant figure out how to add days to the date. Most answers i could find use get date but i want my own date not todays date!

At the same time i'd like to store it as a local storage variable once the days are added (I want to use it later)

Sounds simple right? Can anyone help?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

add days to a date in database and display in ui

Hi -

Unfortunately it is not clear enough. Could you please provide more details, how you storing dates in your DB?

JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

Hi, thanks for the reply.

I am setting the date via the app using the date picker and storing it in the database using the create service. It is stored as a date field in the data base.

Thanks

JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

this is what i have so far

var last, due, text;
last = new Date(value.LastWormed);
due = new Date();
due.setFullYear(2100, 0, 14);

if (last < due) {
text = "I am all up to date with my worming.";
} else {
text = "I am due to be wormed.";
}

return text;

instead of due.setfullyear(xxxxx)
I would like due to be = to LastWormed plus 182 days

does that make sense?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

add days to a date in database and display in ui

Hi JM,

Here is code for you:

pre

var last, due, text;
last = new Date(value&#46;LastWormed);

&#47;&#47;You can adjust days to offset&#46;
var offsetDays = 182;
&#47;&#47;Create due with "last" + offset in days&#46;
due = new Date(last&#46;getTime() + (offsetDays * 24 * 3600 * 1000) );

&#47;&#47;due&#46;setFullYear(2100, 0, 14);

if (last < due) {
text = "I am all up to date with my worming&#46;";
} else {
text = "I am due to be wormed&#46;";
}

return text;

/pre

Regards.

JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

thanks for the reply and your help

I have had a few goes with the example code you gave me and I cant really get this to work at all it returns the "last" date not the "transformed" due date.

i see that moment.js is an available library and wonder if this might be helpful...I can see how to add this as a dependency in server code thanks to your awesome documentation but is there any way to add it to the built in resources in the app settings of the project so that you can use it in the javascript?

JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

had thought about trying to store the due date as a separate date in the database and using something like

$('.new').val(moment($("#DatePicker").val()).add(5, 'days'));

to add the days on the way in

But when i do i get an error saying moment is not defined.

I dont really care how i achieve it at this stage i just want to find a way to get a date stored in my database and add some days to it.

JM
Posts: 0
Joined: Sat Sep 20, 2014 4:34 am

add days to a date in database and display in ui

I have also tried

function addDays(days)
{
var duedate = new Date(this.valueOf());
dat.setDate(dat.getTime() + days);
return duedate;
}

called by

var last, due;
last = new Date(value.LastWormed);
due = new Date(last.getTime()+ addDays(+5));
var y = new Date(due.split(" ")[0]);
var z = y.toDateString();
return z;

Honestly nothing is working not sure what i am doing wrong!

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

add days to a date in database and display in ui

Hy JM,

In given code you have work mechanism to set offset days. Then you need use in accordance to your app logic.

Other very depends on what you want to implement.

So please give us your app public link and describe steps to reproduce your problem and how it should work.

After we will provide you solution.

Regards.

Return to “Issues”