I have a date in string format as follows-
"Fri Jul 11 2003 19:05:44 GMT+0530 (India Standard Time)"
I want to check whether the date is a month old or not.
For this I am doing like this-
var todaysDate= new Date();
todaysDate.setDate(todaysDate.getDate() - 30);
if(Ext.util.Format.dateRenderer("Fri Jul 11 2003 19:05:44 GMT+0530 (India Standard Time)", "D M d Y g:i:s") <= todaysDate)
{
}
It should return true but it is returning false. What I am doing wrong here.
Please help.
You're comparing a renderer to a date, dateRenderer doesn't return a date, it returns a renderer. Renderers are used for example for grid cells, when you have a grid that has a record with a date and you want to display that date in a particular format you use a renderer to tell the grid cell how to format that date.
Check the docs about this: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.Format-method-dateRenderer
Also I believe dateRenderer takes only one argument, you're passing two.
You can use regular Javascript for this:
var oldDate = new Date("Fri Jul 11 2003 19:05:44 GMT+0530 (India Standard Time)");
var newDate = new Date()
newDate.setDate(newDate.getDate() - 30);
if(oldDate <= newDate){
doSomething()
}
Related
Hi I need help with this:
I am working on a macro for which I need to get the value of a cell that has the TODAY() formula in it. My spreadsheet is displaying CET accordingly to my location.
When I do:
var today = sheet.getRange('B1').getValues().flat();
Logger.log(today);
I get:
[Wed Feb 24 18:00:00 GMT-05:00 2021]
On the spreadsheet I see 25.02.2021 11:36 (CET), and in Apps Script, it says current EST should be 25.02.2021 05:36. The date is completely off.
Entire code:
function PrepareColumn() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('TheSheetName');
var dateRange = sheet.getRange(2, 1, 1, 15).getValues().flat();
var today = sheet.getRange('B1').getValues().flat();
Logger.log(today);
}
Two modification points:
Use getDisplayValue to get the value that is displayed in the sheet.
For today you are fetching a single cell, you don't need getValues and then flat.
Replace:
var today = sheet.getRange('B1').getValues().flat();
to:
var today = sheet.getRange('B1').getDisplayValue();
and maybe you want to do the same for dateRange:
var dateRange = sheet.getRange(2, 1, 1, 15).getDisplayValues().flat();
I am having a string which contains 24 hr format.
I am trying to convert it to 24hrs format but it is not changing. below is my code.
$fromtime = '2018-03-28,23:37:50'
[datetime]$fromtime24hrFormat = ([datetime]$fromtime).ToString("yyyy-MM-dd,HH:mm:ss")
$fromtime24hrFormat
Wednesday, March 28, 2018 11:37:50 PM
It shows in PM which is correct. But is it not possible to show it in 24 hr format?
You're so close!
$fromtime = '2018-03-28,23:37:50'
[datetime]$fromtime24hrFormat = ([datetime]$fromtime)
$fromtime24hrFormat.ToString("yyyy-MM-dd,HH:mm:ss")
The problem is that your last line was effectively just dumping the datetime object to the output; which will use a default formatting.
Did you want to add AM/PM to the original input? Try:
$fromtime = '2018-03-28,23:37:50'
$fromtime24hrFormat = [datetime]$fromtime
$fromtime24hrFormat.ToString("yyyy-MM-dd,HH:mm:ss tt")
2018-03-28,23:37:50 p.m.
"p.m." vs PM is caused by my Norwegian regional settings
I'm using D3.js (v3) to plot a time-series graph and I'm trying to figure out the amount of ticks I need for a given month (ie, days). From what I can make of the documentation, d3.time-month should return something from 28 to 31 days, which is what I want, but for some reason I'm obviously missing, I can't seem to get the number I need.
Can anyone help?
This is what I've got so far:
console.log(date); // Fri Jul 01 2016 00:00:00 GMT+0100 (WEST)
monthDays = d3.time.month(date);
console.log(currentMonth+" has "+monthDays+" days."); // July has Fri Jul 01 2016 00:00:00 GMT+0100 (WEST) days.
You're misreading the documentation on intervals : the number of days in the intervals used by d3.time.month have a length between 28 and 31 but the functions are defined as
interval(date)
Alias for interval.floor(date). [...]
and
interval.floor(date)
Rounds down the specified date, returning the latest time interval
before or equal to date. [...]
Basically, d3.time.month(date) will return the first day of the month at midnight, not the number of days in that month.
How to get the number of days then? As far as I can tell, D3 does not expose a way to get the length of the month for a given date. You could of course get the range of days for a given month and extract its length:
var date = new Date(2016, 01, 02); // 2016-02-02
console.log(
d3.time.days(d3.time.month(date), d3.time.month.ceil(date)).length
)
or probably more efficiently use plain JS like in this answer https://stackoverflow.com/a/1185804/1071630 :
var date = new Date(2016, 01, 02); // 2016-02-02
console.log(
new Date(date.getFullYear(), date.getMonth()+1, 0).getDate()
)
var date = new Date(2016, 01, 02);
console.log(
d3.time.days(d3.time.month(date), d3.time.month.ceil(date)).length
)
console.log(
new Date(date.getFullYear(), date.getMonth()+1, 0).getDate()
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
I need to test an agenda and I need getting the actual date and current hour to assert with the agenda values.
This not works:
var d = new Date();
expect(day.getText()).toEqual(d.getDate());
You can get current hour using JavaScript inbuilt getHours() method. Here's its usage -
var cTime = Date().getHours();
or
var d = new Date();
var cTime = d.getHours(); //prints the current hour only
And you can get the actual date using getDate() method which prints a string of values related to current date and time. Sample format: Fri Nov 20 2015 20:24:38 GMT+0530 (IST). Hope it helps
im trying to formatting the date field 'created_at' from Twitter API response with Zend_Date. I want output the date like this:
21 of July of 2009, 12:30:00 (for example)
What format is this?:
Fri Oct 23 15:47:42 +0000 2009
thanks a lot
I've had the best luck just doing
$d = new Zend_Date(strtotime($input));
$twitter_format_out = $d->toString('EEE MMM dd HH:mm:ss Z YYY');
These date are not looking a standard format. Therefore, you have to create a format with the right constants (see them here).
Your first example (21 of July of 2009, 12:30:00):
$format = "d ' of ' MMMM ' of ' YYYY, h:mm:ss";
Your second example (Fri Oct 23 15:47:42 +0000 2009):
$format = "EEE MMM d h:mm:ss Z YYYY";
This formats you can use both for importing a date
$date = new Zend_Date($string, $format);
Or for outputting
$date->toString($format);
Look in the manual for locale support etc.