About SharePoint DateTime issue

%3CLINGO-SUB%20id%3D%22lingo-sub-1190272%22%20slang%3D%22en-US%22%3EAbout%20SharePoint%20DateTime%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1190272%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20question%20is%20when%20I%20put%20a%20data%20into%20a%20List%20such%20as%20Title%20and%20Login%20time%20by%20programming.%20then%20I%20found%20the%20Date%20time%20is%20NOT%20the%20same.%20If%20I%20want%20to%20use%20the%20Login%20Time%20to%20find%20out%20the%20information%2C%20how%20should%20I%20do%20when%20I%20use%20CAML%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Untitled.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172899i52E8C1B86184396D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Untitled.png%22%20alt%3D%22Untitled.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1190750%22%20slang%3D%22en-US%22%3ERe%3A%20About%20SharePoint%20DateTime%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1190750%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F180999%22%20target%3D%22_blank%22%3E%40Will%20%23%20_________%20H%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20you%20elaborate%20how%20did%20you%20update%20the%20data%3F%20And%20specifically%2C%20are%20you%20referring%20to%20the%20extra%20fraction%3Dseconds%20in%20the%20time%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERiwut%20Libinuko%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2F%3FWT.mc_id%3DM365-MVP-4024516%26amp%3Bview%3Do365-worldwide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EManage%20Office%20365%3C%2FA%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Hi there,

 

I have a question is when I put a data into a List such as Title and Login time by programming. then I found the Date time is NOT the same. If I want to use the Login Time to find out the information, how should I do when I use CAML

 

Untitled.png

 

2 Replies

Hi @Will # _________ H ,

 

Can you elaborate how did you update the data? And specifically, are you referring to the extra fraction=seconds in the time?

 

Thanks,

 

Riwut Libinuko

Manage Office 365 

@Riwut Libinuko 

I intercept user login time and put it into the List A, when user logs into the SharePoint. I found the data (Login Time) will be converted to UTC Date Time and saved it into the Database. the Login time on the List View will be Local Time as the shown below. But when I use the same User ID and Login Time to search by CAML language, I cannot found anything. I also list out my source code for you to look at. so do you have any idea on it ?? Thanks

 

DateTime dateTime = DateTime.UtcNow;

                    if (sPList != null)
                    {
                        SPListItemCollection listItemCollection = sPList.Items;
                        SPListItem sPListItem = listItemCollection.Add();

                        sPListItem["Title"] = "0#.w|litwareinc\\administrator";
                        sPListItem["Login_x0020_Time"] = System.TimeZone.CurrentTimeZone.ToLocalTime(dateTime);
                        sPListItem["UTC"] = dateTime;

                        sPListItem.SystemUpdate();

                        SPQuery sPQuery = new SPQuery();

                        sPQuery.Query = @"<Where><And><Eq><FieldRef Name='Title' />" +
                                        "<Value Type='Text'>0#.w|litwareinc\\administrator</Value></Eq>" +
                                        "<Eq><FieldRef Name='Login_x0020_Time' /><Value IncludeTimeValue='true' Type='DateTime'>" + dateTime + "</Value></Eq>" +
                                        "</And></Where>";
                        //sPQuery.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='Login_x0020_Time' />";

                        SPListItemCollection sPListItemCollection = sPList.GetItems(sPQuery);

 

 

Untitled.png