Get date of days in grid

Hello everybody !

I try to get the date of days in grid to compare with current day. I do this :

dateday = (date.getUTCDate()) + "/" + (date.getUTCMonth());

But it return a wrong date. For exemple :
30th august == “29/7”
15th september == “14/8”
1st october == “30/8”

There is 1 day and 1 month of delay. Have you got an idea of the problem ?

Thanks you very much for your help ! And sorry for my bad english …

Hi,
month are zero-based in JS, this means 0 is for January and 11 is for December.
As for the day, if you are in +smt timezone (e.g. UTC+3), and use date like 29th September 2014 00:00:00 (local time, UTC+3) after converting this date to UTC you’ll get 28th September 2014 21:00:00 (utc time, local time - 3)

Btw, if you need to compare dates, why do you convert them to strings? Probably the easier way would be to use the numeric value of date object (you can drop the time part before doing the comparison).

Gantt has a helper for such operations:[code]var date = gantt.date.date_part(new Date(some_date)).valueOf();
var today = gantt.date.date_part(new Date()).valueOf();

if(date < today){
// do something
}[/code]
docs.dhtmlx.com/gantt/api__gantt_date_other.html

Thanks for your answer Aliaksandr but how I get the date of the day on the grid ?

I try also to define a start (current day -1) and end date (current day + 3 month), but i have a blank page …

[code]var startdate = new Date();
startdate = (startdate.getUTCFullYear()) + “,” +(startdate.getUTCMonth()+1) + “,” + (startdate.getUTCDate()-1) ;

	var enddate = new Date();
	enddate = (enddate.getUTCFullYear()) + "," +(enddate.getUTCMonth()+4) + "," + (enddate.getUTCDate()-1) ;
	
	gantt.config.start_date = startdate;
	gantt.config.end_date = enddate; [/code]

Hi,

Please clarify what are you trying to do. I’m not completely understand where and how you getting the dates, and what your code should do

The configs takes the Date objects, not strings
docs.dhtmlx.com/gantt/api__gantt … onfig.html
docs.dhtmlx.com/gantt/api__gantt … onfig.html

I try to define the start and the end date relative to the current date.
I would like to define the start date at the current day less one day and define the end date at 3 month after the current day, like this :

[code]var startdate = new Date();
startdate = (startdate.getUTCFullYear()) + “,” +(startdate.getUTCMonth()+1) + “,” + (startdate.getUTCDate()-1) ;

  var enddate = new Date();
  enddate = (enddate.getUTCFullYear()) + "," +(enddate.getUTCMonth()+4) + "," + (enddate.getUTCDate()-1) ;
  
  gantt.config.start_date = startdate;
  gantt.config.end_date = enddate;

gantt.init(“gantt_here”);[/code]

But with this i 've a probleme because, when we are on the first of the month, the day -1 don’t work …

Hi,
as I said the the date config requires JS Date objects, they won’t work if you assign strings to them. Also note that gantt provides date methods that may simplify work:[code]var today = gantt.date.date_part(new Date());

gantt.config.start_date = gantt.date.add(today, -1, “day”);
gantt.config.end_date = gantt.date.add(today, 3, “month”);

gantt.init(“gantt_here”);[/code]

w3schools.com/jsref/jsref_obj_date.asp
docs.dhtmlx.com/gantt/api__gantt_date_other.html

It’s work very fine. Thank you very much Aliaksandr !