0

I have my database server located in U.S. The user makes entry from INDIA the date must be stored of client and not the server. but, unfortunately the server date is stored in database. I am showing the entries to user only of the current date that are made on the day only. Problem is when user enters record till 12:30 PM(Client Machine) are being displayed to user but after 12:30PM (Client Machine), the entries are not being displayed only the entries made after 12:30 PM(Client Machine) are displayed.Any Idea?

Eg: Entry done at 06/05/2013(DD/MM/YYYY) till 12:30 PM are shown when client machine date is 06/05/2013 11:57 AM but when client machine date is 06/05/2013 12:57 PM the entries enterd are not displayed but entries made after 12:30 PM are displayed. In DB for above eg. created date is stored as 05/05/2013 don't know why? In .cs file:

public static DateTime GetIndianDate(DateTime dateTime)
        {
            return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, TimeZoneInfo.Local.Id,"India Standard Time").Date;

        }

To show todays entries only:

shipments = BLL.GetShipmentsByUserIdNDate(userId, Classes.Common.GetIndianDate(DateTime.Now.Date));

public static List<Shipment> GetShipmentsByUserIdNDate(Guid userId, DateTime dateTime)
        {
            Entities db = new Entities();
            List<Shipment> shipments = (from s in db.Shipments
                                        where s.UserId == userId && s.CreatedDate == dateTime
                                        select s).ToList();
            return shipments;
        }

While Inserting:

shipment.CreatedDate = Classes.Common.GetIndianDate(DateTime.Now.Date);



public static DateTime GetIndianDate(DateTime dateTime)
        {
            return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, TimeZoneInfo.Local.Id,"India Standard Time").Date;

        }

So, How will i store the date of client machine? now it still stores servers date only.

Help Appreciated!

SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
  • possible duplicate of [Globally convert UTC DateTimes to user specified local DateTimes](http://stackoverflow.com/questions/16345862/globally-convert-utc-datetimes-to-user-specified-local-datetimes) – Matt Johnson-Pint May 06 '13 at 13:47

1 Answers1

0

Hey For same I Recommend to Store UTC Date time of every Record when You are saving the records.

When you are fetching the records please get the timezone and manipulate the UTC date

Select getutcdate() --Get UTC Date

Select getdate()--Get Indain Standared Date

Select dateadd(minute,30,dateadd(hour,5,getutcdate())) --Get Indian offset +05:30  

If You want to Update your date from C# Code please refer this one.But in that case also required UTC date

string utcDateString = System.DateTime.UtcNow.ToString();

        DateTime localDate = DateTime.Parse(utcDateString,
                                  CultureInfo.CurrentCulture,
                                  DateTimeStyles.AssumeUniversal);

Hop it Helps you.

Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49
  • hi @Neeraj Dubey i have same problem, can you tell me how can i set user time zone from utc in c# – Alok Dec 06 '13 at 14:46