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 6955259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:42:49+00:00 2026-05-27T14:42:49+00:00

When I insert a SQL DateTime to the database I get 2007-02-07 12:00:00.00 But

  • 0

When I insert a SQL DateTime to the database I get 2007-02-07 12:00:00.00

But I made the Date object like this : 2007-02-07 17:29:46.00

How to get the value of the seconds in the database. It always changes it back to 12:00:00.00

date.setYear(Integer.valueOf(parsedDate[2].replaceAll(" ", "")) - 1900);
date.setMonth(Integer.valueOf(parsedDate[0].replaceAll(" ", "")));
date.setDate(Integer.valueOf(parsedDate[1].replaceAll(" ", "")));
...
java.sql.Date sqlDate = new java.sql.Date(date.getTime());

Should I use any formatters?

  • 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-05-27T14:42:49+00:00Added an answer on May 27, 2026 at 2:42 pm

    java.sql.Date represents a date, not a date and time. From the docs:

    To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be ‘normalized’ by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

    If you want to store a date and time, you should look for another type – e.g. java.sql.Timestamp. EDIT: That’s not suggesting you use a TIMESTAMP column type – as paulsm4 says in the comments, that’s a different thing. However, as far as I can see, JDBC only supports:

    • Date (no, you want a time too)
    • Time (no, you want a date too)
    • Timestamp (includes a date and time, but you don’t want TIMESTAMP SQL semantics)

    I would expect using the Java Timestamp type with a DATETIME column to work, although without the level of precision that Timestamp provides.

    EDIT: After a bit more research, it looks like you may want to use the java.sql.Time type, but with special driver parameters – at least if you’re using the Microsoft driver. See these docs on configuring JDBC for more information.

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

Sidebar

Related Questions

I have data in my database that looks like this: Date (DateTime) Type (varchar)
I'd like to do this in the INSERT SQL. Can anyone show me. Thanks
How can I insert the current date into a datetime field in MySQL database?
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I have a problem inserting a datetime format variable to Sql Server 2005 database.
I'm having to insert values into a new column in our database but I
I am trying to add this query to database and I can't get it
Want to get current datetime to insert into lastModifiedTime column. I am using MySQL
Is there any way to get a table's last modification datetime on Sql Server
I'm attempting to insert rows into a SQL Server CE database, and it's returning

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.