I am receiving a date and time format as a string like this 'MM/DD/YYY HH24MI' e.g 10/02/2010 0730
I am displaying the data in an input field using angular material. I want to validate user's input to match this format to make sure they didn't enter something different. Tried datetime-local but that didn't display it as the format mentioned above.
Thanks in advance.
Related
I am using javascript Date.parse to validate if a date string is a valid date time. I have a specific date time input like this: '8/21/2022 1:45: -04:00' when I do Date.parse('8/21/2022 1:45: -04:00'), the seconds part after : is empty, will get a number which means this date format is correct. I also tried using moment.js v2.29.2 moment('8/21/2022 1:45: -04:00').isValid(), will also get true. Just wondering if anyway to make '8/21/2022 1:45: -04:00' format to invalid? Thank you so much
Could you please share a sample custom object code to restrict the user from selecting the future date and populate a warning message from the questionnaire?
Using version -6.9 SP2
I am not really sure what you really want but what I am guessing is that you want to ensure that user only pick dates earlier than the current date in date input element.
For this you can use the "min" value of the date input field and set it to current date.
I have a form with 2 fields, in one of theme the user will enter a date in the format dd/mm/yyyy and in the other the user will enter a time in the format hh:mm
How can I force this fields formats and how can I validate the date field in order to make sure the date entered is valid and its bigger then the current date and the time field in order to make sure it's a valid time.
I'm using JavaScript in this web site.
For dd/mm/yyyy use
< input type=date>
For hh:mm:
< input type="time">
Set a processing function on form's onsubmit field. In that function you can get a value of dates ( with help of document.getElementBy* functions ) and compare them with DateTime object( use default constructor to get current date).
Hi I am trying to figure out how to display date properly using angularjs.
My system returns the date in this fromat
c_date="\/Date(1151470800000-0500)\/"
I dont know what format is it.
I am displaying it
using <span>{{pro.c_date | date:'medium')</span>
When i run this i get date printed in same format
"/Date(1151470800000-0500)/"
Can anyone suggest how to fix this so date can be displayed properly.
Thanks
the date that you're trying to use is a invalid date or maybe I don't know what format are the system using.
The problem is that angular.js requires a data object for can format it. Not a date string.
I suppose that the date is 1151470800000 miliseconds since the epoch least 0500 for adjust hours or something.
If this is correct, you only need to make c_date a Date object before pass to view.
c_date = "\/Date(1151470800000-0500)\/";
var the_date = eval("new "+c_date.replace(/\\|\//g, ''));
http://jsbin.com/zuwizoxe/3/
Regards!
I'm trying to create an <input type="date"/> in Emberjs and I have two problems:
In my country the date is displayed as DD-MM-YYYY format while the date field requires a MM-DD-YYYY format (and then the browser displays it according to its locale). So the date should be formatted in one way if the browser supports the date input field and in the other way if not
The date is bound to a Date object
I'm using Momentjs for formatting and Ember Data.
I'm trying to extend Ember.TextField like this:
App.DateField = Ember.TextField.extend
value: ( (key, value) ->
if value?
if /Date/.test value.constructor #I assume that if the passed value is a Date object then it is arriving directly from the model
if Modernizr.inputtypes.date
moment(value).format('YYYY-MM-DD')
else
moment(value).format('DD-MM-YYYY')
else # if the passed value is not a Date object then the user is typing into the form
if Modernizr.inputtypes.date
value = new Date('value')
else
value
).property()
type: 'date'
For browsers with date input supports this works.
For the other browsers the date is correctly displayed, but it is saved as a (wrong formatted) string in the model.
How can I maintain the correct formatting while still using Date objects in the backend?
Demo
Update
Thanks to the blog post provided in the accepted answer I was able to update the demo to do what I want (with some weirdnesses, but not relevant at this time)
Demo2
Have look at these two blog posts:
This is a simple date picker:
http://hawkins.io/2013/06/datepicker-in-ember/
This one uses the bootstrap date picker
http://hawkins.io/2013/06/fancy-ember-datepicker-with-twitter-bootstrap/
Hopefully that will help
I don't see any parsing for the string use case. You will need to use something like Date.parse to convert the string entered by the user into a Date object.
if Modernizr.inputtypes.date
value = new Date(value)
else
value = Date.parse(value)