Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:31:48+00:00 2026-06-09T13:31:48+00:00

The user enters a date and a time in separate textboxes. I then combine

  • 0

The user enters a date and a time in separate textboxes. I then combine the date and time into a datetime. I need to convert this datetime to UTC to save it in the database. I have the user’s time zone id saved in the database (they select it when they register). First, I tried the following:

string userTimeZoneID = "sometimezone"; // Retrieved from database
TimeZoneInfo userTimeZone = TimeZoneInfo.FindSystemTimeZoneById(userTimeZoneID);

DateTime dateOnly = someDate;
DateTime timeOnly = someTime;
DateTime combinedDateTime = dateOnly.Add(timeOnly.TimeOfDay);
DateTime convertedTime = TimeZoneInfo.ConvertTimeToUtc(combinedDateTime, userTimeZone);

This resulted in an exception:

The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local

I then tried setting the Kind property like so:

DateTime.SpecifyKind(combinedDateTime, DateTimeKind.Local);

This didn’t work, so I tried:

DateTime.SpecifyKind(combinedDateTime, DateTimeKind.Unspecified);

This didn’t work either. Can anyone explain what I need to do? Am I even going about this the correct way? Should I be using DateTimeOffset?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:31:50+00:00Added an answer on June 9, 2026 at 1:31 pm

    Just like all the other methods on DateTime, SpecifyKind doesn’t change an existing value – it returns a new value. You need:

    combinedDateTime = DateTime.SpecifyKind(combinedDateTime,
                                            DateTimeKind.Unspecified);
    

    Personally I’d recommend using Noda Time which makes this kind of thing rather clearer in my rather biased view (I’m the main author). You’d end up with this code instead:

    DateTimeZone zone = ...;
    LocalDate date = ...;
    LocalTime time = ...;
    LocalDateTime combined = date + time;
    ZonedDateTime zoned = combined.InZoneLeniently(zone);
    // You can now get the "Instant", or convert to UTC, or whatever...
    

    The “leniently” part is because when you convert local times to a specific zone, there’s the possibility for the local value being invalid or ambiguous in the time zone due to DST changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app the user enters the date and then the time. For the
I am having the user enter the date and the time. I need to
Should I store it in a single timestamp/datetime field or separate date and time
I have a form where a user need to enter date and time (2
I am trying to enter the date and time into datetime field in MySql.
When a user enters a date in text box,i've to check ,whether it is
When a user enters captcha and then clicks download on a file hosting site
I have a UI where the user enters a number into a text box,
I want the user to enter an appointment date and time and send him
I'm looking to allow a user to enter a date and time to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.