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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:22:04+00:00 2026-05-13T11:22:04+00:00

I m entering date in front end as 10:00 AM , 12:00 PM etc…(

  • 0

I m entering date in front end as 10:00 AM , 12:00 PM etc…( means 12 Hours format).
now I want to save that value in database in time datatype column. How do I save that AM PM value into time datatype in MySQL and again want to display time appending AM PM on front end?

  • 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-13T11:22:04+00:00Added an answer on May 13, 2026 at 11:22 am

    To insert:

    # replace first argument of STR_TO_DATE with value from PHP/frontend
    TIME( STR_TO_DATE( '10:00 PM', '%h:%i %p' ) );
    

    To select:

    # replace first argument with your time field
    TIME_FORMAT( '22:00:00', '%h:%i %p' );
    

    EDIT:
    I’ll just go ahead and presume you use mysql lib functions.

    // first sanitize the $_POST input
    // also, make sure you use quotes to identify the $_POST keys
    $open = mysql_real_escape_string( $_POST[ 'MondayOpen' ] );
    $close = mysql_real_escape_string( $_POST[ 'MondayClose' ] );
    
    // this is the query, which should work just fine.
    $sql = '
        INSERT INTO
            `table_lib_hours`
        SET
            `day_name` = "Monday",
            `day_open_time` = TIME( STR_TO_DATE( "' . $open . '", "%h:%i %p" ) ),
            `day_close_time` = TIME( STR_TO_DATE( "' . $close . '", "%h:%i %p" ) )
        ';
    
    $result = mysql_query( $sql );
    

    Then to retrieve the values:

    $sql = '
        SELECT
            `day_open_time`,
            `day_close_time`,
            TIME_FORMAT( `day_open_time`, "%h:%i %p" ) as day_open_time_formatted,
            TIME_FORMAT( `day_close_time`, "%h:%i %p" ) as day_close_time_formatted
        FROM
            `table_lib_hours`
        WHERE
            `day_name` = "Monday"
        ';
    
    $resultset = mysql_query( $sql );
    

    This will return a result set where the formatted data is in the *_formatted fields

    EDIT:
    Adjusted %m (month) to %i (minutes). A thank you to Donny for the well spotted slip up.

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

Sidebar

Related Questions

Before Entering data into a database, I just want to check that the database
I am entering records in the MySQL DB. Now I want to have a
I have to textfield in midlet. One for entering the date in format (DD.MM.YYYY),
Assume that I'm adding the date / time into a mysql database and have
Hi following is my loginform in that I want to restrict user from entering
I have a textbox for entering date.Textbox should allow only dd/MM/yyyy format.How can i
I've got a couple of NSTextFields in my application for entering date and time.
When entering a code line in Aptana Studio like <input id=send type=button value=Send onclick=calculate()
If entering a label when a value is specified is redundant do you have
I'm entering data in a datagridview. Say I've entered 678.56 in a cell. Now

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.