0

I inserted current_timestamp in a PostgreSQL database. I want to show the date and time in a PHP program but nothing I do shows the time.

I used - $date = date("m-d-Y h-i-s", strtotime($row['status_date']));

The date is OK, but the time always shows as 12-00-00.

4
  • Can you show us what is the value of $row['status_date'] ? Commented Oct 4, 2013 at 5:37
  • you may mistook, when you insert. Check that code otherwise post that too. Commented Oct 4, 2013 at 5:39
  • possible duplicate of Timestamp to get current time/date Commented Oct 4, 2013 at 5:39
  • $row['status_date'] shows 10-04-2013 12:00:00. Commented Oct 4, 2013 at 6:10

2 Answers 2

1

Possible that the $row['status_date'] has no time on it. Possible output of $row['status_date'] is 2013-10-04 00:00:00. You can try this:

$date = date("m-d-Y h:i A", strtotime($row['status_date'])); 
Sign up to request clarification or add additional context in comments.

1 Comment

Result is 10-04-2013 12:00 AM.
1

If you have php5.4, you can run this script:

<?php echo (new DateTime())->getTimestamp(); 

And if you have stored date time in database:

<?php echo (new DateTime($row['status_date']))->getTimestamp(); 

In PHP5.4 has ben added class member access on instantiation. In older version of php we need two steps:

<?php $date = new DateTime(); echo $date->getTimestamp(); 

2 Comments

echo (new DateTime())->getTimestamp(); throws an error. Expecting `',".
Which version of php do you have?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.