I'm reciving a string with a date in d/m/Y format, and what I need is to convert it to a date and sum X days to it
Asked
Active
Viewed 639 times
-1
-
can you ask what is exacty the pint you are missing? I have a date, I want to sum 1 day to this date, and I'm completely unable to do it, where is exactly the problem? – Mark Nov 15 '13 at 10:37
-
1can you please post an example of the value, showing the exact format you receive the date? – melc Nov 15 '13 at 10:37
-
@Mark I guess I'm missing everything from the context to the code example. – VisioN Nov 15 '13 at 10:38
-
where is the problem? can you re re read please? :) – Mark Nov 15 '13 at 10:41
-
The content is edited, dunno how to explain if now it stills hard tu understand what I'm trying to ask – Mark Nov 15 '13 at 10:52
1 Answers
1
var ajaxDate = [populate with the date from ajax]
var date = new Date(ajaxDate);
var numberOfDaysToAdd = 1;
date.setDate(someDate.getDate() + numberOfDaysToAdd);
Formatting to d/m/y :
var d = date.getDate();
var m = date.getMonth() + 1;
var y = date.getFullYear();
var dormattedDate = d + '/'+ m + '/'+ y;
-
-
-
The problem is that I'm reciving the date in d/m/y format and I'm unable to sum a day I'm geting crazy – Mark Nov 15 '13 at 11:03
-
-
-
FYI providing a date to `Date()` in DD/MM/YYYY format will cause an error – Rory McCrossan Nov 15 '13 at 11:14
-
@Rory i don't think so `var d = new Date(Date.parse("1/1/2013")); /* you get back a Date object */ Date {Tue Jan 01 2013 00:00:00 GMT+0100}` – alex Nov 15 '13 at 11:16
-
-
-
@alex it's because the `Date` object constructor expects the format `MM/DD/YYYY` (amongst others). It'll work for dates like `12/01/2013`, although the date will be Dec 1st, not Jan 12th. – Rory McCrossan Nov 15 '13 at 11:25
-
-
I'm playing with dates like: 15/11/2013 how to sum one or X days to this date in jquery? is it possible? @alex? – Mark Nov 15 '13 at 11:32
-
im afraid the short answer is no. you have to convert in the 'backend' and receive it in a standarized way. – alex Nov 15 '13 at 11:35
-
I was reaching this point and belive me, I can't belive this... but what to do... let's play then... – Mark Nov 15 '13 at 11:36
-