Bootstrap 3 DateTimePicker (eonasdan) - How to quickly select year? (for birthdays) - select

Is it possible in eonasdan's bootstrap 3 datetimepicker to change the dayViewHeaderFormat to show decades or a drop-down menu to choose a year quickly?
Because when someone wants to insert their birthday, it might take a lot of clicks to select the correct year and date. Is there an option to quickly select the correct year? If so, how would this work?

Yes, this is possible using the viewMode function. From the documentation:
viewMode(newViewMode)
Takes a string. Valid values are 'days', 'months', 'years' and 'decades'
For example:
$('#birthday_years').datetimepicker({
format: 'Do of MMMM, YYYY',
defaultDate: new Date(1990, 0, 1, 00, 01),
viewMode: 'years',
});
Here, I've initialised the defaultDate to 1990. You can, of course, change this or use a placeholder to display a text in the input field. Like so: <input ... ... placeholder="Pick your birthday" />.
I've also formatted the date. You can change the date format with these options.
Demonstration of the final result:
> GO TO DEMO

Related

How to set specific Date to the DateTimePicker in Pascal(Lazarus) ? I need set a 01.01.1991 for example? Can't find info about it

Certain date into DateTimePicker (Pascal)
How to add a certain and specific date into DateTimePicker in the Pascal/Lazarus ?
Delphi's TDateTimePicker and FPC's TDateTimePicker both have Date and DateTime properties, which you can set to a specific date, eg:
DateTimePicker1.Date := EncodeDate(1991, 1, 1);

How to pass a date into a ColdFusion collection to be searched

I'm using a ColdFusion collection to search events and I need to pass a date into the collection as a "mmm" so it can be searched. Every time I try I get an error.
custom4="DateFormat(start_date, "mmm")"
Update:
I'm trying to search "month" of the current year
You should use the above code like
custom4=dateFormat(start_date, "mmm")
(Remove the outer double quotes)
Quotes aren't the problem and the suggestion of removing them will actually cause an error. The problem is DateFormat() can't be applied to an entire query column. It's only capable of operating on a single value.
It would help to have more context about what you're trying to achieve, to determine the best approach.
If you want to find items dated in July of a specific year (i.e. July 2019) - then storing the full date, and searching for a date range, is probably a better way to go
If you want to find items dated in July of ANY year, then it's simpler to extract a month number within your SQL query, and store it in the collection. Then you need only search for a number.
Date Range Search
To search for a specific month/year, like July 2019, populate the collection with a timestamp field from your SQL query. Add the suffix _dt to the custom field name so it's treated as a date field
cfindex( query="yourQuery"
, collection="yourCollection"
, action="Update"
, type="Custom"
, Start_Date_dt="yourTimeStampColumn"
, ...
);
In the search criteria, use the date range July 1 through August 1, 2019 (yes - August 1st). Dates must be formatted for Solr, which expects YYYY-MM-DDThh:mm:ssZ. NB: Dates should be in UTC (not local time).
cfsearch (name="searchResults"
, collection="yourCollection"
, criteria=' start_date_dt:[2019-07-01T04:00:00Z TO 2019-08-01T04:00:00Z}'
);
Explanation/Notes
[ and } - Brackets indicates a range (i.e. from dateX TO dateY)
[ - Square bracket means inclusive (i.e. include July 1st)
} - Curly bracket means exclusive (i.e. exclude August 1st)
Field names should be in lower case
Month Number Search
To search for a specific month in any year, like July, extract the month number within your SQL query. (The exact syntax will be DBMS specific. You didn't mention which one you're using, so see your database's documentation on date functions.) Add the suffix _i to the custom field name so it's handled as an integer
cfindex( query="yourQuery"
, collection="yourCollection"
, action="Update"
, type="Custom"
, monthNumber_i="theMonthNumberColumn"
, ...
);
Then simply search for the desired month number, i.e. 7 - July
cfsearch ( name="searchResults"
, collection="yourCollection"
, criteria=' monthnumber_i:7 '
);
Full Example
Sample Query
sampleData = queryNew("MyID,Start_Date,MonthNumber"
, "integer,timestamp,integer"
, [{MyID=10, Start_Date="2019-06-30 12:30:00", MonthNumber=6}
, {MyID=20, Start_Date="2019-07-01 00:00:00", MonthNumber=7}
, {MyID=30, Start_Date="2019-07-01 16:30:00", MonthNumber=7}
, {MyID=40, Start_Date="2019-07-31 23:50:00", MonthNumber=7}
, {MyID=50, Start_Date="2019-08-01 00:00:00", MonthNumber=8}
]);
Create Collection
cfcollection ( action="create", collection="MyCollection");
Update Collection
cfindex( query="sampleData"
, collection="MyCollection"
, action="Update"
, type="Custom"
, key="MyID"
, title="SampleData"
, MonthNumber_i="MonthNumber"
, Start_Date_dt="Start_Date"
, body="MyID"
);
Find July, by month number
cfsearch ( name="monthNumberResults"
, collection="MyCollection"
, criteria=' monthnumber_i:7 '
);
// results
writeDump( var=monthNumberResults, label="Month Number Search" );
Find July 2019, by date range
// Search range: July 1 to August 1, 2019
fromDate = "2019-07-01";
toDate = dateAdd("m", 1, fromDate);
// Format dates for Solr
// Note: DateTimeFormat uses "n" for minutes. Valid in CF2016 Update 3 or higher
fromDate = dateTimeFormat( dateConvert("local2UTC", fromDate), "yyyy-mm-dd'T'HH:nn:ss'Z'");
toDate = dateTimeFormat( dateConvert("local2UTC", toDate), "yyyy-mm-dd'T'HH:nn:ss'Z'");
cfsearch ( name="dateRangeResults"
, collection="MyCollection"
, criteria=' start_date_dt:[#fromDate# TO #toDate#} '
);
// results
writeDump( var=dateRangeResults, label="Date Range Search" );

Why is my formula returning a number instead of a date?

When trying to add days to a date in another column the value returns as a number, not a date.
I have tried to set the column format as the date for both columns B and C. I also tried using the DATEVALUE() function, but I don't think I used it properly.
=ARRAYFORMULA(IF(ROW(B:B)=1,"Second Notification",IF(LEN(B:B), B:B+1,)))
I want the value in column C to return as a date.
use this with TEXT formula:
={"Second Notification";
ARRAYFORMULA(IF(LEN(B2:B), TEXT(B2:B+1, "MM/dd/yyyy hh:mm:ss"), ))}

MomentJS date string adds one day

I don't understand why this date is saved as +1 day:
startdate = "2017-11-29T23:59:59.999Z";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives 30/11/2017
But if I do:
startdate = "2017-11-29";
var new_date = moment(startdate).format('DD/MM/YYYY'); // --> gives the correct date 29/11/2017
Any ideas?
Here is a jsfiddle showing this: http://jsfiddle.net/jbgUt/416/
Thanks!
If a time part is included, an offset from UTC can also be included as +-HH:mm, +-HHmm, +-HH or Z.
Add utc() to avoid it.
moment(startdate).utc().format('DD-MM-YYYY')
or
moment.utc(startdate).format('DD-MM-YYYY')
If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment()
Late to the party on this one, but I did just convert a few of our product's date-time objects to https://moment.github.io/luxon/
Takes out the need for the .utc() method above.

Jasper Reports - Add one day to a Date Parameter

I'm creating a Jasper report that includes the following parameters:
DATESTART (Date)
DATEEND (Date)
These parameters indicate a date range for a field called DATECREATED (Timestamp) which includes times. I would like the date range to be INCLUSIVE, that is, if I filter for "Jan 1, 2009" to "Jan 31, 2009", any DATECREATED value on Jan 31, 2009 (such as "Jan 31, 2009 15:00") will be included in the report.
When I used Crystal Reports in the past, I used the DATEADD function to create a filter expression like the following:
{DATECREATED} >= {DATESTART} and {DATECREATED} < DATEADD("d", 1, {DATEEND})
(I realize that this isn't syntactically correct, but you get the idea.)
Is there any way to do something similar in Jasper Reports?
If you understand French, there the same question is asked in this thread
(the only difference is that it is about adding a month)
The proposed solutions are following:
SQL
Do it with SQL statement directly in the query (if your data source is a SQL datasource of course).
With MySQL you can do something like
DATE_ADD($P{DATEEND},INTERVAL 1 DAY);
more information: Date and Time Functions (MySQL doc)
JAVA
The other solution is to use the Java possibly of the Date object:
I proposed something like :
$P{DATEEND}.setDay($P{DATEEND}.getDay()+1)
But I did not try it (and it is probably wrong).
Maybe you need to defined a new Date Variable DATEEND_1
with a value expression like :
new Date($P{DATEEND}.getTime() + 24*60*60*1000)
or
new java.util.Date($P{DATEEND}.getTime() + 24*60*60*1000)
And use this new variable in your query V{DATEEND_1}.
(again I am not sure of it)
Try this:
new java.util.Date($P{DATEEND}.getTime() + 24*60*60*1000)
Another option is to use the Groovy SDK that comes bundled with the latest versions.
new Date().plus(1) //Today plus one day = tomorrow.
Or to be more complete - add your two parameters DATESTART and DATEEND and set the default expression to be the above code. Then in your query add the following to the where clause:
DATECREATED >= $P{DATESTART} and DATECREATED < $P{DATEEND}
or depending on your SQL variant.
DATECREATED BETWEEN $P{DATESTART} AND $P{DATEEND}
Suppose you have a Parameter PARAM1 and you want to add 366 days to param1 then you can do it by following way
1) Declare another parameter say $P{finalDate}
2) Code like below for $P{finalDate} as the Default Value Expression
new Date($F{PARAM1}.getTime() + 366L*24*60*60*1000)
Dont forget to put L after 366 . Without putting L , it may not work properly and may not give accurate date.
It will add 366 days to PARAM1
We have built a library of static date-related functions, which can be used like this:
DateUtil.add(NOW(), 0, 0, 1)
The above would get you a date one day into the future (the arguments are year, month, day). It would be nice to have a DATE_ADD function supported directly by JasperReports. Sounds like a patch waiting to be submitted.
DAYSINMONTH($P{Date}) >= (DAY($P{Date})+ 1)
?
DATE(YEAR($P{Date}),MONTH($P{Date}),DAY($P{Date})+1)
:
((MONTH($P{Date}) + 1) > 12) ? DATE(YEAR($P{Date}) + 1,1,1) : DATE(YEAR($P{Date}),MONTH($P{Date}) +1 ,1)
I am sorry for necro'ing this post but I thought that I should share this as another alternative to the options posted above. You just need to change all the $P{Date} to be your parameter!
You can create a class to help you, which has a static method which processes your parameters (or modify class JasperUtils by adding a static method). This way you can have amethod returning a boolean which will act exactly as the filter you need.
package com.package_name.utils;
public class JasperUtils2 {
public static Boolean filterDate(Date dateStart, Date dateEnd, Date dateCreated) {
if (dateCreated.compareTo(dateStart) < 0) return false; // dateCreated is greater or
// equal to dateStart
if (dateCreated.compareTo(dateEnd) > 0) return false; // dateCreated is smaller or
// equal to dateEnd
// you can combine the two conditions into one. I wrote it like this to be more obvious
}
}
To use this method, you need to import the class created (Edit -> Report import directives -> new import ---- this may differ for different versions of iReport). Then, you can use the method in static way:
JasperUtils2.filterDate(..., ..., ...)