I have a domain class where i have a field where there are two dates namely start date and stop date. I have mysql database linked with my application. While entering details in webpage, i need to make sure that the date given does not overlap with older enteries in the database.
My domain class is defined below:
class Assigned {
String assignedTo = " "
Date assignedDate
Date expiryDate
String ownedBy
String additionalInformation = " "
static constraints = {
assignedTo()
assignedDate()
expiryDate()
ownedBy()
additionalInformation()
}
}
when i press create in the view, i need to validate that no other things overlap with the current dates i have given.
please help. Thanking you in advance..
If you want to check the period between the given start and end date with the other entries.
Write a method that check for each stored period
- if the start date is greater equals the stored start date
AND
- if the start date is less equals the stored end date
Do this also for the end date.
In the controller call the method from the save/update method. If start or end date overlap with another period you create a validation failed message + redirect to the create/edit view.
Related
I want to know how to make the date automatically change the year only
For example, if I have this date in the database 9/21/2020
I want the year to change every year, for example, we are now 2022. The date in the database is 9/21/2022
In your controller you can do something like
while (myDate.Year < DateTime.Now.Year)
{
myDate = myDate.AddYears(1);
}
I have a field last_update in which I want to store the current datetime as a user edits a form in form view. Basically I need to default the value of last_update to the system's date.
I tried using:
<field name="last_update" default_last_update="datetime.now()"/>
But, it is not working.
In the python file:
from datetime import datetime
last_update = fields.Datetime(string='Last Update',default=lambda self: fields.datetime.now())
In Every model, you will always have "write_date", which stores last record update time.
Still if you wants to add this field and update it every time when record update then you can set default when record create and inherit write() method to update every time when record update, set current time in that field as following :
last_update = fields.Datetime(string='Last Update',default=fields.Datetime.now)
#api.multi
def write(self, vals):
vals.update({'last_update':fields.Datetime.now})
return super(<your_class_name>, self).write(vals)
You Can Also Use This:
from datetime import datetime
last_update = fields.Date(string='Last Update',default=datetime.now())
I have a form that contains a Datepicker and in the email that is sent on submission the date is formatted with a time.
How do I remove the time from the date?
Thanks
You can either change the property to just Date, without the time element, or you can use ToString() method for the DateTime within C#:
https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx
The format without time would look something like this:
yourDate.ToString("DD/MM/YYYY");
I have a single week fullcalendar on a page containing user schedules by name. I have a text box where a user can enter a username to search by partial stringmatch. My plan was to grab the val() of the textbox, change the {events:"/myfeed"} and refetchEvents if needed. Here is what I did:
$("#username").on("input", function(){
// reload calendar with partial string match of textbox
var username = $("#username").val(); // get the partial username
var thismorninghash = morninghash; // make a copy of the main parameter hash
thismorninghash['events']='/main/feed/user?user=' + username; // change the feed
$("#calendar-am").fullCalendar(thismorninghash);
});
My problem is that I can fetch the new feed but for every character typed, I get a whole new 1 week calendar. I do not get duplicate events in the calendar (as others ask about) I get a brand new calendar. If I type "smith" I get the original plus 5 new calendars. I'm perplexed at this!
Remove existing calendar before load again,
$("#calendar-am").fullCalendar("destroy");
I have a date field in my grid. I can't seem to figure out how can I turn off the validation if a user doesn't enter a date. In my data model the date property is not decorated with required attribute. Also in the database that I am using the date column is allowed a null and has a default value. I also turned off the Client Validation in the web config file. But still can't figure out why the date field has client validation turned on. The telerik version I am using is 2011.2.712.340.
So I was able to find out how to turn off the client validation if the user is not required to enter a date while filling a form. When declaring the data model if you have the property to as nullable:
public DateTime? YourDateProperty {get; set;}
then you can edit or insert a new record. In my case I had the date field as one of the columns in the grid and I was having problems where I could not insert a new record without the user having to enter a date.