Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 4th, 2013, 09:56 AM
Registered User
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default How to use addHours function with Linq?

Hi, I am using the modified version of the content of the book and i use "Events" instead of "Genres" and the "Comments" as is. Although i have my DB engine resides in the USA hence we have 8 hours of time differences and basically i want to correct this time differences by adding "8hrs" to the comments "CreateDateTime" column when the user adds his/her comment. Since we use Linq and i don't how to achieve this! Or Can we use TimeZoneInfo convertTime function of conversion?? Any help will be appreciated. Thanks!
Here is my linq anonym type as follows,
where a.Authorized == true
select new
a.Reviews(This is my Comments where i stuck!!!)
Old April 4th, 2013, 02:40 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

If you want to change it just when you display it, you can query the data first, and then loop over it. Depending on the resultset, you may need a double loop:

foreach (Event event in events)
  foreach(Review review on evemt.Reviews)
         review.CreateDateTime = review.CreateDateTime.AddHours(8);
Alternatively, you can do this when you insert the data, so the data is in a more consistent state in the database.

Hope this hepls,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
master777 (April 4th, 2013)
Old April 4th, 2013, 06:16 PM
Registered User
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default Excellent! Thanks

I have been searching for this approach for days! may be like 2 weeks. So Thank you ever so much! Excellent!!!

Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ or T-SQL? DennisE ASP.NET 4 General Discussion 2 October 29th, 2011 11:36 AM
LINQ to EF and LINQ to SQL sophia BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 19th, 2011 12:16 PM
Linq Problem sridharnetha C# 2005 1 December 29th, 2009 07:31 AM
LINQ vaibhavgoe LINQ 4 December 21st, 2009 03:49 PM
LINQ Tutorial manish .NET Framework 3.5 1 August 13th, 2009 01:07 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.