Date-picker date format and datepicker options - angular-ui-bootstrap

i have a few problems with the date-picker, especially regard the date format.
I need to make a date-format like that 'ddMMyyyy' without symbols like slash or minus.
this is my Markup
HTML
<input type="text" datepicker-popup="{{format}}" show-weeks="false" ng-model="Fromdate" show-button-bar='false'>
and that's my format in javascript
JS
$scope.format='ddMMyyyy';
is this the right way to make the format?
Because if i choose the date from the datepicker nothing seems to go wrong but if i type directly the text a errors happens.
the first four number were evaluated like year, so if i type '01022014' i aspect first february 2014 instead the date-picker evaluate 14 of no month (20 is not a month) of the 0102 year.
Second question, i'd like to put the option of the date Picker in the js file and not in the markup, for example:
HTML
<input type="text" datepicker-popup="{{format}}" ng-model="Fromdate" datepicker-options="options">
js
$scope.options={
show-weeks:"false"
show-button-bar:'false'
}
but in that way it seems doesn't work, what is thee right way to do that?

Use Uib-Datepicker
Js:
$scope.dateOptions = {
showWeeks: false,
format: 'ddMMyyyy'
};
HTML:
<uib-datepicker ng-model="selectedDate" datepicker-options="dateOptions" ng-required="true"></uib-datepicker>

Related

How to add today's date in Marp markdown

all
I am looking for a simple way to add today's date in my marp markdown. Something like
{{ date }}
Any idea?
Thanks
Here is one way using the Date() function in JS. This could then be customised to display exactly what you wanted (date, time, specific date format etc.)
With this method though, if viewing as a HTML slide deck then the datetime will change each time the page is loaded.
If you wanted to insert a static time (e.g. file save date etc), perhaps the easiest way would be to just do a regex replace on a certain phrase eg. {{ date }} as above, before you get Marp to convert the document.
---
marp: true
---
Refresh to see changes...
<p id="date1"></p>
<p id="date2"></p>
<p id="date3"></p>
<script>
const now = new Date()
document.getElementById("date1").innerHTML = now;
document.getElementById("date2").innerHTML = now.toLocaleDateString("en-US");
document.getElementById("date3").innerHTML = now.toLocaleDateString("en-US", {weekday: 'long'});
</script>

jqueryui 1.10.3 datepicker format using . as separator

I have inherited some code that appears to use jqueryui 1.10.3 to incorporate a datepicker.
When I click the textbox to bring the datepicker up and choose a date, the format looks like
21.03.2020
However, if I click on the textbox again the format is
21/03/2020
The slash is the desired functionality. When the initial date is selected I want it to display as dd/mm/yyyy. How can I stop the date parts being separated by .
I have tried examining the jquery-ui-1.10.3 file to see if I can work out where the . separator is being applied but I haven't been able to come up with anything.
Somewhere in your web page or script section you should have code that looks like the code below.
This is where you can set your date time picker format. Look at the format date section.
$(document).ready(function () {
$("#<%= TextBoxName.ClientID %>").datetimepicker({
dayOfWeekStart: 1,
lang: 'en',
startDate: '<%= TextBoxName.Text %>',
step: 30,
formatTime: 'H:i',
formatDate: 'Y.m.d'
});
});
See more help here: jquery datetime picker

datePicker showing one day previous wrong day in grails

In edit and print (html print) mode, I have get one day previous date. I have used mysql database. My domain like
class Immunization {
------
Date doseOneDue
Date doseOneGiven
----
}
I have use datepicker in view like
<g:datePicker name="doseOneDue" precision="day" noSelection="['': '']"
value="${immunizationInstance?.doseOneDue}"
relativeYears="[-5..5]" default="none"/>
Now problem is:
suppose doseOneDue is '2015-08-30', But when I showing it in datePicker in edit mode then it is selecting '29 - 08 - 2015', Also in html print option showing also one day less. How can handle this problem.

dateTimePicker UTC Bootstrap

Each time that I choose a value from the datetimepicker and I send the info to the controller on the server side we are receiving a different time on the server side."caused by the UTC"
I would like to know how to apply the UTC time on the datepicker in order to avoid this error.
<input type="text" id="datePickId" class="form-control" ng-model="dateFrom" datepicker-popup="{{'dd-MM-yyyy'}}" is-open="openedTo" close-text="Close" />
http://momentjs.com
You might want to use moment.js plugin for date handling on javascript, in the controller you simply do the follow:
var tmp = moment($scope.dateFrom).utc().format();
or
var tmp = moment.utc($scope.dateFrom, 'MM-DD-YYYY').format();
It returns the UTC time formatted, hope it helps

How to make jqueryUI datepicker submit in a different format than what is being displayed?

I'm working on some internationalization using jQueryUI. I have a DatePicker control on a form that is properly working in the French language.
When I select a date, for example August 15, 2012, the DatePicker will display 15 Aoû, 2012 as I would expect. My issue however, is that when the form is posted, the value of the DatePicker is posted as '15 Aoû, 2012' which now needs to be translated on the server before it can be saved properly.
My question is, is there a built-in way inside the jQueryUI DatePicker so that I can have it always post to the server in a consistent format, regardless of which language the control is being displayed in? If there isn't a built-in way, what options exist for achieving this?
I realize that I can change the dateformat to something like 08/15/2012 instead of using the textual representation, however this isn't what I want to do.
There's 2 configuration options for that: altField and altFormat. http://api.jqueryui.com/datepicker/#option-altField
If you specify an altField, that field will be updated too, and will have the altFormat.
Normally you will want make the altField a hidden field, soyou can ignore the regular field and send to db the altField.
As you'll have noticed, supplying a dateFormat works well for newly entered dates, but it does not alter the value attribute which was already supplied to the date input field. It took me some time and I'm not sure whether this solution is ideal, but here's my situation explained and the code which solves it. Might help others with the same problem in the future. In my example I'm using dd/MM/yyyy as the display format.
The page contains any number of date input fields, which may or may not already have a value attribute supplied in the format yyyy-MM-dd, as specified by W3C.
Some browsers will have their own input control to handle dates. At the time of writing, that is for instance Opera and Chrome. These should expect and store a date in the abovementioned format, while rendering them according to the client's regional settings. You probably do not want/need to create a jqueryui datepicker in these browsers.
Browsers which don't have a built-in control to handle date input fields will need the jqueryui datepicker along with an 'alt', invisible field.
The invisible, alt input field with the yyyy-MM-dd format must have the original name and a unique id in order for forms logic to keep working.
Finally, the yyyy-MM-dd value of the display input field must be parsed and replaced with its desired counterpart.
So, here's the code, using Modernizr to detect whether or not the client is able to natively render date input fields.
if (!Modernizr.inputtypes.date) {
$('input[type=date]').each(function (index, element) {
/* Create a hidden clone, which will contain the actual value */
var clone = $(this).clone();
clone.insertAfter(this);
clone.hide();
/* Rename the original field, used to contain the display value */
$(this).attr('id', $(this).attr('id') + '-display');
$(this).attr('name', $(this).attr('name') + '-display');
/* Create the datepicker with the desired display format and alt field */
$(this).datepicker({ dateFormat: "dd/mm/yy", altField: "#" + clone.attr("id"), altFormat: "yy-mm-dd" });
/* Finally, parse the value and change it to the display format */
if ($(this).attr('value')) {
var date = $.datepicker.parseDate("yy-mm-dd", $(this).attr('value'));
$(this).attr('value', $.datepicker.formatDate("dd/mm/yy", date));
}
});
}
<input type="text" name='fieldName' id="datepicker" value="" style="width: 100px;" />
<script type="text/javascript">
$( "#datepicker" ).datepicker( "option", "dateFormat", 'dd/mm/yy' );
$( "#datepicker" ).datepicker();
</script>
It appears someone else had this question or a similar one prior to yours.
If you read this stackoverflow answer, the author was trying to show the date in one format and pass the data to MySQL in another format.
The prior answer in that link gets you set up to access the selected value as a variable. Now all you need is to wire in a parseDate to your selected date variable.
<script type="text/javascript">
$('#cal').datepicker({
dateFormat: 'dd M yy',
onSelect: function(dateText, inst) {
var dateAsString = dateText; //the first parameter of this function
var newDateFormat = $.datepicker.parseDate('dd-mm-yyyy', dateAsString);
}
});
</script>
Check the parseDate link for settings and formatting.
Hope this helps!
Basically, you should not re-format the date. Instead, you should read JavaScript's Date object from Datepicker, via getDate() method. Then, you need to pass it to server.
The question is how. Basically, what you want is some common format. If you use JSON the answer is very simple, just put date object and JSON's stringify() function will automatically format it to ISO8601.
As you may see from Wikipedia, ISO8601 was designed to interchange date and time reliably, therefore that's what you should use.
It might be helpful to know that modern web browsers support Date object's toISOString() method.
As #Pawel-Dyda mentioned,
There's a
getDate() method
var currentDate = $( ".selector" ).datepicker( "getDate" );
Here's an example of what it returns: Wed Jan 20 2016 00:00:00 GMT+0300.
You can parse it in Javascript, PHP, in SQL or whatever.
MySQL parsing examlple:
select str_to_date('Wed Jan 20 2016 00:00:00 GMT+0300','%a %b %d %Y %H:%i:%s');
Returns:
2016-01-20 00:00:00
Solution working for ASP.NET
#using (Html.BeginForm("ActionName", "ControllerName"))
{
#Html.HiddenFor(m => m.DateFrom)
#Html.HiddenFor(m => m.DateTo)
<div class="form-group">
#Html.LabelFor(m => m.DateFrom)
<input id="datepicker-date-from" type="text" class="form-control datepicker" value="#Model.DateFrom.Date.ToString("dd.MM.yyyy")"/>
</div>
<div class="form-group">
#Html.LabelFor(m => m.DateTo)
<input id="datepicker-date-to" type="text" class="form-control datepicker" value="#Model.DateTo.Date.ToString("dd.MM.yyyy")" />
</div>
<input type="submit" class="btn btn-sn btn-primary" value="Download" />
}
#section scripts {
<script type="text/javascript">
$(function () {
$("#datepicker-date-from").datepicker(
{
dateFormat: "dd.mm.yy",
altField: #Html.IdFor(m => m.DateFrom),
altFormat: "yy-mm-dd"
});
$("#datepicker-date-to").datepicker(
{
dateFormat: "dd.mm.yy",
altField: #Html.IdFor(m => m.DateTo),
altFormat: "yy-mm-dd"
});
});
</script>
}

Resources