1

I have a list called employees and it has a column named Birthday. I have to campare if today is birthday,

how can I query in this way:

 DateTime Date = DateTime.Now;

 SPQuery = new SPQuery();
 query.Query = "<Where><Eq><FieldRef Name='Ditlindja' />" + "<Value Type='DateTime'>" + date + "</Value></Eq></Where>";

this code is not working with string type it works but not with DateTime why?

2

Please use below query to compare birthday with current date.

SPQuery = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Ditlindja' /><Value Type='DateTime'><Today /></Value></Eq></Where>";

By using variable

 DateTime date = DateTime.Now;

     SPQuery = new SPQuery();
     query.Query = "<Where><Eq><FieldRef Name='Ditlindja' /><Value Type='DateTime'>" + date + "</Value></Eq></Where>";
  • yes this works but i need to make it with local variable – Nderon Hyseni Jun 7 '16 at 8:52
  • Check updated answer.... If it is not working than you need to convert your ate with utc.. – Hardik Jun 7 '16 at 10:36
  • no it is not working with variable – Nderon Hyseni Jun 7 '16 at 12:43
  • Have you tried to convert it to UTC or in ISO format? – Hardik Jun 7 '16 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.