How to show current day date in meta title of a page?

Hello,
Is there any method to show current date in meta title of a page in a html website ?

<html>
<head>
<meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <title> </title>
    <meta name="description" content="There may be many reasons why you cannot login to webmail. Check your username and password.">
<script>
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday");
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");
var now = new Date();
document.title(now.getDate() + " " + monthNames[now.getMonth()] + ", " + now.getFullYear());
var docTitle = document.title;
</script>
</head>
<body>
	demo
</body>
</html>

This is the code which is showing date in page , but I want to show the date in head title.

Sure thing. The most reliable way is using PHP or some other server-side language to add the date when it generates the page.

I’ve moved this thread from JavaScript to the PHP forum so that they can help to advise further.

How to do it?

Hi there shobhapatwal,

this code…


<!DOCTYPE HTML>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title><?php echo date("D/M/Y");?></title>

</head>
<body>

</body>
</html>

…saved as a PHP file would produce this output…

<title>Thu/Dec/2019</title>

coothead

1 Like

As mentioned use serverside PHP to find the result of the date(…) function:

https://www.php.net/manual/en/function.date.php

Generate the index.html webpage source and insert the results from the date function.

Ninjaad by @coothead

1 Like

Hi there John,

I was just going to edit my post for a further
reading link
but you beat me to it. :winky:

Nijaad by @John_Betong

coothead

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.