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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:06:34+00:00 2026-06-08T18:06:34+00:00

I am inserting a date into a database with NOW() then I query the

  • 0

I am inserting a date into a database with NOW() then I query the result. Here is the code.

    function get_content($id = ''){

if($id != ''):
    $id = mysql_real_escape_string($id);
    $sql = "SELECT * FROM cms_content WHERE id = '$id'";

    $return = '<p><a href="index.php">Back to Content</a></p>';
else:
    $sql = "SELECT * FROM cms_content ORDER BY id DESC";
endif;

    $res = mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($res) != 0):
        while($row = mysql_fetch_assoc($res)) {
            echo '<h1><a href="index.php?id=' . $row['id'] . ' "> ' . $row['title'] . '</a></h1>';
            echo '<p>' . stripslashes($row['body']) . '</p>';
            **echo '<p>' . $row['date_posted'] . '</p>';**
            }
    else:
        echo '<p> You broke it!, this post dosn\'t exsist!';
    endif;

    echo $return;

The

echo '<p>' . $row['date_posted'] . '</p>'; 

is where I echo the date. When I echo this from the database I get 2012-07-25 19:00:46, because that’s what is in the database. My question is how would I echo the day, then echo the month, then the year. Ideally these would all be separate echos so I could style each differently.

  • 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-08T18:06:35+00:00Added an answer on June 8, 2026 at 6:06 pm

    Since the format is known, you can simply use this:

    list($year,$month,$day) = explode("-",substr($row['date_posted'],0,10));
    

    Then you can echo those variables however you want.

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

Sidebar

Related Questions

I have problem when inserting a date to my database Insert query: INSERT INTO
I'm now inserting a date/time data into my date/time field in the database. I
I am inserting a date into my database, the value which comes from: s.theDate
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I'm using oracle 11g. I'm inserting date and time using function SYSDATE into column
I have the following code which should be inserting into the database x amount
I am having some trouble inserting an array into the sql database. my error
Before inserting into the database, I'm using the following code to check for duplicates.
For inserting special characters in data like (,')etc., I am using mysql_real_escape_string() function &
I'm trying to insert registration data into a database but my php code isn't

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.