Jump to content

help with displaying date 3 days ago


dombrorj

Recommended Posts

I'm trying to get whatever the date was 3 days ago to display in an html document. And I need is the month on one line and the day on another.

 

If today's date is January 2nd, for example, the date has to display December 31.

 

So my html looks like this...

 

<head>
</head>
<body>
<p>the date 3 days ago was:
<br>
December
<br>
31
</body>

 

Can someone help me with the php code to use here? What I've found so far won't actually display anything in my browser, so I may be doing it entirely wrong. I use other php scripts, and am certain my server has php 5 enabled. But maybe there's something else that has to be enabled?

 

Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/
Share on other sites

you can use strtotime with date e.g

 

<?php
echo date('F d', strtotime("-3 days"));
?>

 

Excellent, thanks! I couldn't get it to work at first when the doc was saved as an html file. Once I saved as a php file and uploaded to server, it worked. Is that necessary? (clearly don't know what I'm doing)

 

One other question... the format of the month is spelled out entirely, i.e. "December"

 

Is there an easy way to make the months abbreviated, i.e. "Dec"

 

Thanks!

You would have to save your files with .php that is how the server identifies and parses out your php files unless you configure the server differently,

 

for different date formatting you can see the following link

 

http://php.net/manual/en/function.date.php

 

there are examples which show you how you can format your date

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.