Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-08-12 01:15:18

BryanA.
Member
From: Maryland, USA
Registered: 2007-08-12
Posts: 101

How does anyone show the current date?

<txp:time />

Neat, but useless on its own I think. I entered this in the Header Form on a whim when <txp:date /> gave me an error suggesting I was close. I don’t know what it is that came up, like a Stardate or something, but can it be handled in such a way as to show visitors the CURRENT DATE!

I hope the answer is somehow ‘yes, and without plugins.’ Got a killer looking date/time stamp on WebWriter3 and UXmag.com, and since I see it CAN happen, would now like to know how for my own txp installation.

I’m new, down with HTML and not so much CSS and .php so a little extra dumbing up on an answer would help greatly!


Voice Actor – starting up a site for that good book stuff.

Offline

#2 2007-08-12 01:52:49

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: How does anyone show the current date?

I don’t pretend to understand any of this, but this is the code used in a TXP template that seems to work:

<txp:php>echo date(“F jS Y”, time() + tz_offset());</txp:php>
<br />
<txp:php>echo date(‘g:i A’, time() + tz_offset());</txp:php>

Hope that helps!


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#3 2007-08-12 05:15:13

BryanA.
Member
From: Maryland, USA
Registered: 2007-08-12
Posts: 101

Re: How does anyone show the current date?

Those letters are familiar to me for some other reading I’ve done (my understanding being weak as well) and I think that code works when a php sheet has been made to place the date and time in the MySQL databases. My txp reported back:

Parse error: parse error, unexpected T_STRING
and
Parse error: parse error, unexpected ‘:’

No sweat though – do you have the name of the template that you used? It might include that php sheet… Thanks for the quick post!


Voice Actor – starting up a site for that good book stuff.

Offline

#4 2007-08-12 05:57:58

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: How does anyone show the current date?

Sure: This one

Cheers


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#5 2007-08-12 09:40:10

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: How does anyone show the current date?

The code that Neil quotes does not require a separate “sheet”. It is placed in the sidebar form template where required. I use a very similar version in my header form templae at The Bomb Site. As far as I am aware it makes no entry in the database. It simply calls (via PHP) for the server date and time and then adds or subtracts any “offset” you may have specified.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#6 2007-08-12 09:51:25

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: How does anyone show the current date?

Make sure you’re using the right quoting characters:

<txp:php>echo date('F jS Y', time() + tz_offset());</txp:php>
<br />
<txp:php>echo date('g:i A', time() + tz_offset());</txp:php>

Last edited by ruud (2007-08-12 09:51:36)

Offline

#7 2007-08-12 13:21:36

BryanA.
Member
From: Maryland, USA
Registered: 2007-08-12
Posts: 101

Re: How does anyone show the current date?

Changing this to [solved] – thanks to all of you! And how bizarre; the code triggered those errors the first time but works today in the sidebar and the header with the exact same code. Go figure.


Voice Actor – starting up a site for that good book stuff.

Offline

#8 2007-08-12 21:30:21

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: How does anyone show the current date?

ruud wrote:

Make sure you’re using the right quoting characters:

Thanks Rudd. I should have checked for that after pasting the code… ;-)


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#9 2007-08-13 15:42:05

BryanA.
Member
From: Maryland, USA
Registered: 2007-08-12
Posts: 101

Re: How does anyone show the current date?

Ohhh…. I see it. ‘/” difference.

Any chance that the month “F” can be called up as the three letter version instead of the whole name? FEB rather than FEBRUARY? I know of some site that goes through hoops to explain that formatting the php server time/date can be controlled with CONVERT functions like:

PRINT ’5) HERE IS DD MON YY FORMAT ==>’ +
CONVERT,GETDATE,6)

delivers “HERE IS DD MON YY FORMAT ==> 13 AUG 07” which is what I’m after if I’m allowed to be picky about the date’s display. :) But I don’t know how to apply CONVERTing within TXP. The very quirky work in progress is www.dinarius.com/commentable

Website discussing converting time/date display:
http://www.databasejournal.com/features/mssql/article.php/2197931

My limp efforts to style the date is a blatant borrow from uxmag.com at the moment.

Last edited by BryanA. (2007-08-13 15:46:29)


Voice Actor – starting up a site for that good book stuff.

Offline

#10 2007-08-13 16:12:36

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: How does anyone show the current date?

See the date PHP manual, which has details on all the formatting codes you can use.

Offline

Board footer

Powered by FluxBB