# PHP Date Question

**URL:** <https://forum.kirupa.com/t/php-date-question/25927>\
**Category:** programming\
**Created:** [July 17, 2003, 6:39pm UTC](https://forum.kirupa.com/t/php-date-question/25927 "2003-07-17T18:39:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sorcerer](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Sorcerer](https://forum.kirupa.com/u/Sorcerer)\
**Post date:** [July 17, 2003, 6:39pm UTC](https://forum.kirupa.com/t/php-date-question/25927/1 "2003-07-17T18:39:08Z")

</div>

I am trying to write a news managment system in PHP and had a couple questions.

For each news article I want to store the date it was submitted. I then want to only display items that are newer than 30 days on the main news page. Is there a way I can get a date in php so that i can just subtract 30 from it and use that in an if statement?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2003, 6:41pm UTC](https://forum.kirupa.com/t/php-date-question/25927/2 "2003-07-17T18:41:00Z")

</div>

```php

$d = date("d");
$m = date("m");
$y = date("y");

```

that gives you the day the month and the year as seperate variables so it is easier for you to mess around with… you should be able to subtract easily from one number instead of a string…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2003, 7:26pm UTC](https://forum.kirupa.com/t/php-date-question/25927/3 "2003-07-17T19:26:40Z")

</div>

If I use those I have to account for how many days are in each month to figure out if something is 30 days old. What I was looking for was possibly something with the year and then the number of days from the beginning of the year. I have seen formats like this before (can’t remember what this date format is called) and was wondering if PHP had anything like this.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2003, 8:45pm UTC](https://forum.kirupa.com/t/php-date-question/25927/4 "2003-07-17T20:45:28Z")

</div>

$day = date(“z”);

[http://us3.php.net/manual/en/function.date.php](http://us3.php.net/manual/en/function.date.php)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 17, 2003, 8:47pm UTC](https://forum.kirupa.com/t/php-date-question/25927/5 "2003-07-17T20:47:05Z")

</div>

Ok, now I feel dumb, I looked through that table before asking but must have just not seen it.

Thanks for the help.
