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
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.