I am using AjaxPro to retreive database, the date field return Sat Apr 3 00:00:00 UTC+0700 1982 i want to format it like "dd/mm/yyyy".
Assuming you are getting a DateTime value from the server, you can do something similar to this:
Visit http://www.ajaxpro.info/Examples/DataType/default.aspx
and run the following code in Firebug.
var result = AJAXDemo.Examples.DataType.Demo.GetDateTime(new Date()).value;
var year = result.getFullYear();
var month = result.getMonth() + 1;
var day = result.getDate();
var formattedDate = [day, month, year].join('/');
console.log(formattedDate);
Related
I'm trying to create a metric to give me the number of request between two relative dates.
I tested this:
Request M =
VAR StartDate = DATEADD('Request'[request_date],-20,DAY)
VAR EndDate = DATEADD('Request'[request_date],0,DAY)
RETURN
calculate(sum('Request'[request_count]),DATESBETWEEN('Request'[request_date], StartDate, EndDate))
And I have the error : "A table of multiple values was supplied where a single value was expected "
My column request_date looks like this :
5 july 2022
5 july 2022
5 july 2022
5 july 2022
6 july 2022
6 july 2022
7 july 2022
...
--> All my dates are present more than once.
So I tried to add a "firstdate", like this:
VAR StartDate = DATEADD(FirstDate('Request'[request_date]),-20,DAY)
VAR EndDate = DATEADD(FirstDate('Request'[request_date]),0,DAY)
This time I have no error, but I don't get the right value. Could you help me please ?
Add a (unique) Date table to your model and setup a one-to-many relation between 'Date'[date] and your 'Request'[request_date]
Then use
Request M =
VAR StartDate =
DATEADD('Date'[date], -20, DAY)
VAR EndDate =
DATEADD('Date'[date], 0, DAY)
RETURN
CALCULATE(
SUM('Request'[request_count]),
DATESBETWEEN('Date'[date], StartDate, EndDate)
)
I am using AWS amplify for my project and trying to save the selected date from datepicker to the model.
DatePicker is giving the date in DateTime object, when i try to convert it to TemporalDate its giving me a day before date. i.e if i select todays date and assigning it to the TemporalDate then i am getting yesterday's date.
Here is my code :
var d1 = TemporalDate(pickedDate);
var d4 = TemporalDate(pickedDate.toUtc());
var d2 = TemporalDate(pickedDate.toLocal());
var d3 = TemporalDate(pickedDate).getDateTime();
pickedDate is holding today's date but the d1,d2,d3,d4 all is having yesterday's date.
Expected result is to get the today's date in the TemporalDate variable.
You need to parse the date. It is showing a day before because it is on the universal date. So you just need to convert the universal date to local date.
var dateTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(selectedDate.toString(), true);
var dateLocal = dateTime.toLocal();
I wondered if anyone could help. I have a script where I am pulling out data from a spreadsheet list, where this is a match for this week (basically an events list, to produce a weekly agenda). I will use a for loop to increment the days to add on, but I am just trying to make it work for one day for now...
The first column is the data in format dd/mm/yyy
I am trying to take today's increment by 1 and then search through the list to find a match. The searching etc, I can make work, but the date part is just not playing. I wondered if anyone could advise.
E.g. Date Column A:
06/07/2021
06/07/2021
01/11/2021
01/11/2021
01/11/2021
01/11/2021
02/09/2021
02/09/2021
var selectedDate = row[0];
selectedDate = Utilities.formatDate(new Date(selectedDate), "GMT+1", "dd/MM/yyyy");
var currdate = new Date();
currdate = Utilities.formatDate(new Date(selectedDate), "GMT+1", "dd/MM/yyyy");
var daystochange = 1;
var newdate = new Date(currdate.getFullYear, currdate.getMonth, currdate.getDay+daystochange );
Could anyone help?
Thanks
Only use Utilities.formatDate() to output dates, not to work with dates.
The JavaScript date object has all you need to work with dates and compare. When you use the Utilities function it converts it to a string, and so you lose all the functionality of the Date object.
Also bear in mind that if you have dates, that are formatted as dates in your sheet, they will automatically be returned as Date objects.
For example, if your sheet has a date in cell A1
var date = Sheet.getRange("A1").getValue()
date instanceof Date // true
Once you have your date, if you want to add one day to it, you can take an approach similar to what you have already done:
var selectedDate = new Date(2021, 1, 15)
var newdate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate() + 1);
console.log(newdate) // Tue Feb 02 2021 00:00:00
Note - use getDate to return the day of the month, getDay only returns day of the week.
To check if two dates are the same, you can write a function to compare:
function isSameDate(a, b) {
return a instanceof Date &&
b instanceof Date &&
a.getYear() === b.getYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
}
This function will return true if the dates are the same.
Reference
Date
I have a fusion table with two date_time columns. The fist one is the start date (Startdatum) and in the other column is the end date (Einddatum).
I want to do a query with the current date, and only show the KML-lines on a map where the current date lies between the start and end date.
I tried to use the code below to create a string with a date format:
var time_date = new Date();
var day = time_date.getDate();
var month = time_date.getMonth()+1;
var year = time_date.getFullYear();
var date = (year+"."+month+"."+day);
To show the KML-lines on the map I tried to use the following code:
layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col2",
from: "1mOMP1seJq4FdiNTugsfylZaJc8sKcSlfJKUuTJjv",
where: "'Startdatum' <= date AND 'Einddatum' >= date"
},
options: {
styleId: 2,
templateId: 2
}
});
Unfortunatly the map shows all the KMS-lines regardless what date is in one of the columns.
What am I doing wrong?
the where-clause is wrong, it has to be
where: "Startdatum <= '"+date+"' AND Einddatum >= '"+date+"'"
the date-format seems to be wrong. Although the used format yyyy.MM.dd is defined in the documentation, it doesn't work. The format yyyy-MM-dd currently works for me(but it's not defined in the documentation).
var date = (year+"-"+month+"-"+day);
(in case that day and month be less than 10 they wouldn't match the pattern, but that doesn't seem to be an issue)
Beyond that: when you fix these 2 mentioned parts it currently works(for me), but I've tried it a couple of hours ago and got unstable results.
I am developing an application which needs the current date from the device, but it only needs day-of-week, month, and day-of-month, like Friday October 14
I have tried this code with Calendar. How do I convert Date to String? Is this possible to get date in this format?
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
System.out.println("Date" + c.getTime());
and my output : `Fri Oct 14 16:17:03 Asia/Calcutta 2011`
You could use SimpleDateFormat:
SimpleDateFormat fmt = new SimpleDateFormat("EEEE MMMM dd");
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
System.out.print("Date ");
System.out.println(fmt.format(c.getTime()));
If you need those values in different Strings it gets a little bit more complicated (using DateFormatSymbols to get the month/weekday names):
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
DateFormatSymbols dateSymbols = new DateFormatSymbols();
String[] monthsText = dateSymbols.getMonths();
String[] weekdaysText = dateSymbols.getWeekdays();
String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
String month = monthsText[c.get(Calendar.MONTH)];
String weekday = weekdaysText[c.get(Calendar.DAY_OF_WEEK)];
System.out.format("day: %s, month: %s, weekday: %s", day, month, weekday);