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

  • Home
  • SEARCH
  • 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 6653959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:19:58+00:00 2026-05-26T01:19:58+00:00

I am a newbie. I started php coding few days back. I want to

  • 0

I am a newbie. I started php coding few days back. I want to copy a “datetime” datatype in php to fields that are of “date” and “time” datatype.

I have kept the field name datetime_info for the datetime value. It exists in try1 table. date is the name of field for “date” datatype and time is the name for “time” datatype. These two exist in try2 table.

Here is what I have written.

$result = mysql_query("SELECT * FROM try1");

while ($row = mysql_fetch_array($result))
{

    $result_update = mysql_query("INSERT INTO try2 (date, time) VALUES ('".$row_team['datetime_info']."', '".$row_team['datetime_info']."')");
    if (!$result_update)
    die('Error: ' . mysql_errno() . mysql_error());
}

The values stored in “try1” table are:

id  datetime_info
1   2008-10-02 00:00:00
2   2008-10-09 00:00:00

The expected response should be the date and time stored in respective fields. However, the output is

id  date        time
2   0000-00-00  00:00:00
3   0000-00-00  00:00:00

Can anyone explain me why and how? I tried a lot of sites but did not find any proper explanation for this. Thank you in anticipation.

Regards,
BasicGem

  • 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-26T01:19:59+00:00Added an answer on May 26, 2026 at 1:19 am

    First of all, you shouldn’t have to use PHP to do the hard work here. MySQL is very powerful to do these kinds of tasks on it’s own.

    Since you are copying all rows from table try1 into try2 (but splitting the datetime column), the following should work:

    INSERT INTO
      `try2`
      SELECT
        null, DATE( `datetime_info` ), TIME( `datetime_info` )
      FROM
        `try1`
    

    What this does is: for every record found in try1 insert the following values into try2:

    • null means use the auto_increment functionality of the id column in try2 (this is presuming the id column is indeed an auto incrementing primary key field)
    • DATE( `datetime_info` ) means use the DATE part of the datetime_info column of try1
    • TIME( `datetime_info` ) means use the TIME part of the datetime_info column of try1

    Simply doing mysql_query( $sql ) where $sql is a string that represents above query should suffice then. No need to loop through any results first with PHP.

    I was gonna write a PHP solution as well, but others have already done so. I would have suggested this answer.

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

Sidebar

Related Questions

I'm a totally newbie in class writing in PHP, started a couple days ago.
I am a newbie just started exploring Grails so that I can recommend this
I am a super newbie php person. Just started scripting a week ago. I
Being a GWT newbie, I want to create GWT frontend and a PHP backend,
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
I'm a newbie at Flash, so started playing with a pretty standard code sample:
I am just started using Git, so I apologize if it is a newbie
Good morning, Apologies for the newbie question. I'm just getting started with ASP.NET internationalization
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that

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.