How to “Filter” data having “DateTime” format according to the “CurrentDateTime” in SharePoint?
I have a datetime data field named “CreatedOn” (DateTime), I want to apply filter where I want to Display items only “GreaterThan Or EqualTo” the “CurrentDateTime”.
I tried with this CAML Query in the where condition but didn’d succeed, it was filtering only according to current date not the “CurrentDateTime”
<Where> <Geq> <FieldRef Name="CreatedOn"/> <Value Type="DateTime" IncludeDateTime="TRUE"> <Today/> </Value> </Geq> </Where>
Any help is appreciated.
Vinu
This was the solution I got from Emir Liu
Hi Vinu,
Please create a Data View Web Part instead of List View Web Part in this way in SharePoint Designer:
Insert > Data View > Empty Data View > Select your list > Select the fields you need to display in the web part > Insert them as multiple list items.
Because that we need to use formula as the filter value, but List View Web Part is not supported to use formula as the filter value, then Data View Web Part is needed.
Use following formula as the filter value, so that data view will only display the items which their CreatedOn field is greater than or equal to current date time.
number(ddwrt:FormatDateTime(string(@CreatedOn),3081,’yyyyMMdd0000′))+number(ddwrt:FormatDateTime(string(@CreatedOn),3081,’HHmm’))>= number(ddwrt:FormatDateTime(string(ddwrt:TodayIso()),3081,’yyyyMMdd0000′))+number(ddwrt:FormatDateTime(string(ddwrt:TodayIso()),3081,’HHmm’))
Add the formula this way:
Put your mouse with the data view > Click Filter button under Options tab in SharePoint Designer ribbon > Enable “Add XSLT Filtering” option > Click Edit button > Paste above XPath here.
Let me know if you have any question.
Thanks & Regards,
Emir
Thank you
Vinu