In my project I allow to register anyone and he can schedule a test on certain date.

But problem is when registered user set a test on a date assuming local time,
but the server which hosting the site is in U.S hense there is mismatch occurs.

Can anybody tell me how other web applications (running accross multiple countries)accept and store dates in databases.

Dani AI

Generated

The thread correctly spots two separate issues: culture/formatting and time-zone semantics. called out culture differences and pointed toward a canonical storage idea. The following gives a compact, practical strategy suited for multi-country apps.

Capture the user time context on the client (IANA zone when available, fallback to numeric offset) and send it along with the local date/time string. Store three bits of data so intent is preserved: the raw local value the user entered, the user time-zone identifier, and a canonical timestamp for queries/sorting. For timestamped events use a timezone-aware column (SQL Server has datetimeoffset) or a UTC column plus the zone id. For date-only events (no time-of-day) store the date and the zone id instead of blindly converting to UTC; that avoids day-shifts around DST boundaries.

Client and server snippets:

// get IANA zone (preferred) and offset fallback
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; // e.g. "Asia/Kolkata"
const offsetMinutes = new Date().getTimezoneOffset();
// parse ISO datetime from client and keep as DateTimeOffset on server
DateTimeOffset dto = DateTimeOffset.Parse(clientIsoString);

Notes and cautions: prefer IANA names (they carry DST rules) over fixed offsets; save the zone id on the user profile to avoid repeating capture; use server APIs that understand DST (TimeZoneInfo on .NET). See the JavaScript timezone API and .NET/SQL types for implementation details: Intl.DateTimeFormat.resolvedOptions(), DateTimeOffset (.NET), and datetimeoffset (Transact-SQL).

Recommended Answers

All 2 Replies

while Saving the Data To the
Database please write the following like in the .cs file.
Hope this may help u

CultureInfo cinfo = new CultureInfo("hi-IN");

CultureInfo Provides information about a specific culture (called a "locale" for unmanaged code development). The information includes the names for the culture, the
writing system, the calendar used, and formatting for dates and sort strings.

You might also try converting to universal time when storing in the database, and then applying the time zone when pulling it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.