Hi,
Sitecore 7.0 - 7.5 have a bug in it regarding DateTime. It will not store or retrieve time part from date. The following solution will target this DateTime Format bug in Sitecore version 7.2 until Sitecore will ship fix.
The problem statement is "
Currently Sitecore does not provide Time Stamp in DateTime Fields".
In my case: I am trying to get latest items from sitecore using lucene index search.The default date format is "yyyyMMdd" but my requirement is "yyyyMMddHHmmss"
Please follow the steps below to solve this issue.
Step 1:
Make a web config file in my case DateTimeFormat.config. Copy paste following code in it
Make a folder "DateTimeFormat" in website App.Config/Include and copy this file in the newly created folder.
Step 2:
In Visual Studio make a new project "CustomDateTimeFormat" of type class library. Create a class "DateTimeFieldReader" inherit it from "FieldReader". Copy paste follwoing code
This class will be called when ever user will publish sitecore items or rebuild index in sitecore. This class format the datetime fields according to the IndexDateFormat provided in web.config file above.
Step 3:
Create another class with the name "DateTimeConverter" inherit it from "System.ComponentModel.DateTimeConverter". Copy paste following code
This class will convert the date time in the format provided in web.config file when ever an item will be accessed.
Conclusion:
This will fix the date time format issue in search index of sitecore 7.2 but will produce another bug in Sitecore.
Sitecore has introduced speak api in 7.0 and above. This will get some items from search index in sitecore like when ever you open an media library by clicking "Browse" link on any Image Field. It will fetch images thumbnails from search index. So, we have changed date format and we have to tell sitecore speak api to parse date format according to our new format "yyyyMMddHHmmss" because its default format is "yyyyMMdd". Other wise it will give date time parse error like "S
tring was not recognized as a valid DateTime"
For solution click on Media Library Browser Thumbnail Issue in Sitecore 7.2