# How to format date variable

**URL:** <https://www.phphelp.com/t/how-to-format-date-variable/36594>\
**Category:** Beginners - Learning PHP\
**Created:** [September 30, 2025, 7:27pm UTC](https://www.phphelp.com/t/how-to-format-date-variable/36594 "2025-09-30T19:27:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![babystarman](https://www.phphelp.com/user_avatar/www.phphelp.com/babystarman/32/4453_2.png) [@babystarman](https://www.phphelp.com/u/babystarman)\
**Post date:** [September 30, 2025, 7:27pm UTC](https://www.phphelp.com/t/how-to-format-date-variable/36594/1 "2025-09-30T19:27:58Z")

</div>

Hi, I am stumped by one small problem. I have a routine which gets data from a DB and displays it.  
It works very well, apart from how the date is displayed. I have tried several possible ways of formatting the date but it always comes out in the SQL format: 2025-10-5 for example. Here’s a bit of what I have:

```auto
while ($row = $res->fetch_assoc()){
	$nicedate = date('m-d-Y',strtotime($row['talkdate']));	
		?>
		<h2><?php echo $nicedate; ?>: <?php echo($row['talktitle']); ?> </h2>
```

Everything works properly - apart from how the date is displayed. I know that ‘m-d-Y’ isnt how I want the string to look (I just did it like that so I could see a difference between what I want and what I get), I just don’t want it to be ‘2025-10-5’!  
(some of the above is coming out in a bold font by the way)

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [September 30, 2025, 7:38pm UTC](https://www.phphelp.com/t/how-to-format-date-variable/36594/2 "2025-09-30T19:38:34Z")

</div>

> [@babystarman](#):
>
> (some of the above is coming out in a bold font by the way)

To post code on the forum, either put bbcode `[code][/code]` tags or markdown three back-ticks ``` on their own lines, above and below your code. I have edited your post above.

Your posted code works for me and outputs an expected - 10-05-2025: some title

---

<div class="post-metadata">

**Author:** ![babystarman](https://www.phphelp.com/user_avatar/www.phphelp.com/babystarman/32/4453_2.png) [@babystarman](https://www.phphelp.com/u/babystarman)\
**Post date:** [September 30, 2025, 8:22pm UTC](https://www.phphelp.com/t/how-to-format-date-variable/36594/3 "2025-09-30T20:22:39Z")

</div>

Ah, the variable to be formatted is ‘talkdate’. ‘talktitle’ comes out as it should (i.e., the value of the ‘talktitle’ variable).  
Just checked what you said and… thanks again! I played about with the date format and it now comes out as it should (Sunday 5 October 2025)  
I feel like sending you a xmas card! 😁
