0

I have a column type DATE in mysql database and want to get date in format like this - 21-jan.

$stmt = $db->query('SELECT id, date, title, category FROM posts ORDER BY date DESC');
while($row = $stmt->fetch()){
    $date = strtotime($row['date']);
    $date = date_format($date, "d-M"); // line 49

Warning:
date_format() expects parameter 1 to be DateTimeInterface, integer given... on line 49

Any help ?

2 Answers 2

1

Try to do this:

$date = strtolower(date("d-M", $date));

Take a look at date function: http://php.net/manual/pt_BR/function.date.php

Sign up to request clarification or add additional context in comments.

1 Comment

It works, but can I have 21-jan instead of 21-Jan ?
1

Use date function instead of date_format:

$stmt = $db->query('SELECT id, date, title, category FROM posts ORDER BY date DESC');
while($row = $stmt->fetch()){
    $date = date("d-M", strtotime($row['date']));
    $formatedDate = strtolower($date);

3 Comments

It works, but can I have 21-jan instead of 21-Jan ?
@bonaca unfortunately date() function doesn't do that but you can accomplish it with help of strtolower() function
Thanks a lot. Solved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.