get last modified date of sharepoint group. - sharepoint-2007

How to get last modified date of a sharepoint group.
how to get date when a user is added to a sharepoint group.
thanks for your help.
Arvind

You can get the "Creation" and "Last Modified" Date through following Code:
SPList groupInformationList = SPContext.Current.Web.SiteUserInfoList;
SPListItem grpItem = groupInformationList.Items.GetItemById(group.ID); // Pass the ID of group
// OR, SPListItem grpItem = web.SiteUserInfoList.GetItemById(web.SiteGroups["group_name"].ID);
string groupCreationDate = Convert.ToDateTime(grpItem[SPBuiltInFieldId.Created]).ToString("MM/dd/yyyy hh:mm tt"); //Group Creation Date
string groupLastModifiedDate = Convert.ToDateTime(grpItem[SPBuiltInFieldId.Modified]).ToString("MM/dd/yyyy hh:mm tt"); // Group Modification Date

I do not know of an out of the box way to do this. The SPGroup and SPUserCollection classes do not contain dates. And even looking in the content database (which is unsupported), neither the Groups or GroupMembership tables have dates.

Related

Entity Framework - Oracle Date Comparison

I have an Oracle database column of type date, the date format is dd-MMM-yy, when I try and retrieve an entity from the database using the Entity Framework and a date comparison I get back no records.
I use this method for the query
var calendar = _repository.Single<Calendar>(c => DbFunctions.TruncateTime(c.CALNDR_DATE) == DbFunctions.TruncateTime(calendardate));
I've also tried it in various ways:
var calendar = _repository.Single<Calendar>(c => c.CALNDR_DATE) == calendardate);
I thought this one would work for sure:
var calendar = _repository.Single<Calendar>(c => c.CALNDR_DATE.Year == calendardate.Year && c.CALNDR_DATE.Month == calendardate.Month && c.CALNDR_DATE.Day == calendardate.Day);
No matter what I've tried I cannot get the method to bring back a calendar record even though I have verified there is a record with the date I'm passing. The value in the calendardate variable is formatted as mm/dd/yyyy. If I query the database directly using SQLDeveloper I get back a result when I search with this query select * from table where CALNDR_DATE = '17-DEC-15'
But no result if I search for: select * from braidss.tmmis98 where CALNDR_DATE = '12/17/2015' - This is what I see if I check what is generated by the LINQ
My question is how can I handle this comparison so the dates match? I have tried several different ways but nothing has worked so far.

Rails string to DOB year

I'm currently storing strings formatted like "01/01/1989" (client side validation) for the bday field.
I want to parse out the year and store it as a variable, like this:
#bdayyear = current_user.bday.year
I want that to bring back "1989"
How would I go about doing that?
Just do using #strftime and ::strptime :
s = "01/01/1989"
current_user.bday.strptime(s, "%d/%m/%Y").strftime("%Y")
# => "1989"
Convert it into a DateTime object and you can call year on it
>> DateTime.parse("01/01/1989").year
=> 1989
If the format is always consistent the why not just use the string
"01/01/1989".slice(-4..-1)
"01/01/1989"[-4..-1]
Or
"01/01/1989".split(/\W/).pop
These will all return "1989" without converting it to a date

Grails - Convert String data to Date

Lets say, i have a "Book" class with field "availableOn"(as shown below).
class Book {
String availableOn;
}
The fields holds values
"All days" or
String representation of a date. For example "13/06/2012"
How can i get all Books that are available within next two days? The below code would throw an exception ("java.util.Date cannot be cast to java.lang.String")
def books = c.list(){
between('availableOn', new Date(), new Date() + 2)
}
PS : Am working on a legacy DB, and so am not suppose to change the schema :(
I think there are 2 problems which the between statement will have:
availableOn cannot be converted to a Date for comparison when its value is All days
Even when availableOn has a date value in it, it is not converted to a Date for the comparison
I'd try something along the lines of this:
def now = new Date()
def books = Book.findAllByAvailableNotEqual("All days").findAll { book ->
Date.parse('dd/MM/yyyy', book.availableOn) > now && Date.parse('dd/MM/yyyy', book.availableOn) < now+2
}
Clearly, this can be done in a nicer way (adding some methods to the domain class for example), but this should illustrate my idea...
I don't have a criteria based solution, but you can try something like this:
Book.executeQuery(
"select book from Book book where book.availableOn = :availableOn or to_date(book.availableOn, :format) between (:startDate, :endDate) ",
[availableOn:"All days", format: "dd/MM/yyyy", startDate: startDate, endDate:endDate])
The problem with my solution is that this query becomes DB dependent. to_date is an Oracle function. You may want to alter this to fit your database
You can use format on a date to get desired string format of it.
new Date().format('dd/MM/yyyy')
And your criteria would get modified to
def books = c.list(){
def todayDateStr = new Date().format('dd/MM/yyyy')
def twoDaysAfterTodayDateStr = (new Date()+2).format('dd/MM/yyyy')
or{
between('availableOn', todayDateStr, twoDaysAfterTodayDateStr)
eq 'availableOn', 'All Days'
}
}
Test if the str comparison works, otherwise other ways has to be used. Sending from phone, excuse my typos.
UPDATE
The above would fail in peculiar cases when dates are like "01/01/2013" and "07/11/2011".
Alternatively, you can use sqlRestriction but in that case it gets tightly coupled with the underlying database. Something like this can be done if Oracle db is used:
def books = c.list(){
def todayDateStr = new Date().format('dd/MM/yyyy')
def twoDaysAfterTodayDateStr = (new Date()+2).format('dd/MM/yyyy')
or{
sqlRestriction "to_date(available_on, 'DD/MM/YYYY') between to_date(todayDateStr, 'DD/MM/YYYY') and to_date(twoDaysAfterTodayDateStr, 'DD/MM/YYYY')"
eq 'availableOn', 'All Days'
}
}

Saving and Querying a Date in GORM Grails

I have a database table TableA, which has a column 'theDate' for which the datatype in the database is DATE.
When I save a java.util.Date to 'theDate' through GORM it appears to save just the date value when I look at the data in the table by just executing select * from TableA.
However, when I run a query such as:
select * from TableA where theDate = :myDate
No results are found, but if I run something like;
select * from TableA where theDate <= :myDate
I do get results.
So it's like the Time is relevant.
My question is how do I save a Date and query for a Date ignoring the Time completely and just matching on an exact Date only?
Thanks.
note: I have also tried using sql.Date and util.Calendar but to no success.
clearTime()
You can use clearTime() before saving and before comparing to zero out the time fields:
// zero the time when saving
new MyDomain(theDate: new Date().clearTime()).save()
// zero the target time before comparing
def now = new Date().clearTime()
MyDomain.findAll('SELECT * FROM MyDomain WHERE theDate = :myDate', [myDate: now])
joda-time plugin
An alternative would be to install the joda-time plugin and use the LocalDate type (which only holds date information, no times) instead of Date. For what it's worth, I don't think I've worked on a project with dates without using the Joda plugin. It's completely worth it.
If you have date saved without clearing you could retrieve it using range, as Jordan H. wrote but in more simple way.
def getResults(Date date) {
def from = date.clearTime()
def to = from + 1
def results = MyDomain.findAll("from MyDomain where dateCreated between :start and :stop" ,[start:from,stop:to])
}
Your question may be a duplicate. See Convert datetime in to date. But if anyone has more recent information, that would be great.
If that doesn't help, you can hack it the way I might, with a BETWEEN restriction, e.g.
def today = new Date()
def ymdFmt = new java.text.SimpleDateFormat("yyyy-MM-dd")
def dateYmd = ymdFmt.format(today)
def dateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
def startDate = dateTimeFormat.parse("${dateYmd} 00:00:00");
def endDate = dateTimeFormat.parse("${dateYmd} 23:59:59");
MyDomain.findAll("from MyDomain where dateCreated between ? and ?", [startDate, endDate])
It's definitely not pretty, but it may get you where you're going.
I figured it out.
I used DateGroovyMethods.clearTime to clear the time value before saving.
You can use the DB type date not datetime , in the filed type

All day event icalendar gem

I am using the below to setup an event to export to ical with the icalendar gem.
#calendar = Icalendar::Calendar.new
event = Icalendar::Event.new
event.dtstart = ev.start_at.strftime("%Y%m%d")
event.dtend = ev.end_at.strftime("%Y%m%d")
event.summary = ev.summary
#calendar.add
In order to make an event all day it needs to look like this:
DTSTART;VALUE=DATE:20101117
DTEND;VALUE=DATE:20101119
Right now I am using
event.dtstart = "$VALUE=DATE:"+ev.start_at.strftime("%Y%m%d")"
This will output
DTSTART:$VALUE=DATE:20101117
and then I replace all ":$" with ";" with
#allday = #calendar.to_ical.gsub(":$", ";")
Is there a more direct way to save dates as all day?
I played around with this and figured out one way. You can assign properties to the event dates, in the form of key-value pairs. so you could assign the VALUE property like so:
event = Icalendar::Event.new
event.dtstart = Date.new(2010,12,1)
event.dtstart.ical_params = { "VALUE" => "DATE" }
puts event.to_ical
# output
BEGIN:VEVENT
DTSTAMP:20101201T230134
DTSTART;VALUE=DATE:20101201
SEQUENCE:0
UID:2010-12-01T23:01:34-08:00_923426206#ubuntu
END:VEVENT
Now the fun part. Given a calendar you can create an event and pass in a block which initializes the date with its properties:
calendar.event do
dtstart Date.new(2010,11,17), ical_params = {"VALUE"=>"DATE"}
dtend Date.new(2010,11,19), ical_params = {"VALUE"=>"DATE"}
end
So this thread seems quite old (and did not solve the problem with the most recent version of the icalendar gem - 2.3.0). I've recently had to create "all day" calendar events in ics format. I've found this to be a much better solution (and seems to work the way you'd expect calendars to handle it) - see the snippet below
date = Date.new(2010,11,17)
event = Icalendar::Event.new
event.dtstart = Icalendar::Values::Date.new date
event.dtstart.ical_param "VALUE", "DATE"
event.dtend = Icalendar::Values::Date.new (date + 1.day)
event.dtend.ical_param "VALUE", "DATE"
puts event.to_ical
The above code produces the following output:
BEGIN:VEVENT
DTSTAMP:20150521T162712Z
UID:4c239930-15ba-44b4-a045-c6fae3d858d2
DTSTART;VALUE=DATE:20101117
DTEND;VALUE=DATE:20101118
END:VEVENT
Note that the Date does not have a time associated with it. The code in the prior reply currently produces the time. I had to dig into the source code for icalendar to figure out this solution.
I hope this helps someone else.
Cheers!

Resources