Hi all
I'd like to change the year in the theme.

e.g. From year 2010 to display YC-112

Basically I have this code which sorts the correct year:

$year = date('Y');
$month = date('m');
$day = date('d');
$year = $year - 1898;
$date = 'YC-' .$year. '-' .$month. '-' .$day;
echo $date

But would like to apply it in the node.tpl.php like in this post:
http://drupal.org/node/339435 (apologies I can't get the code to display right)

Basically I'm stuck in retrieving the actual post date, converting it as above and then displaying it.

But need some way to make it work and I'm a little stumped at how to take the next step. Can anyone please give me some pointers on this?

Any help appreciated, thank you.

Comments

mshepherd’s picture

you have no semicolon after the echo statement.

Cromicon’s picture

Ok thanks. But what I was looking for was how to retrieve the actual post date, then apply the code above to minus 1898 from the year and then apply that to the printed post via node.tpl.php. This bit of code below I think gets the actual date but I need to know how to manipulate it using the code in my OP.

print format_date($node->created, 'custom', "l, F j, Y - H:i");

dman’s picture

From a very basic RTFM, http://php.net/manual/en/function.date.php

Wouldn't

$year = date('Y', $node->created);

etc, do it?

There is probably a much cleaner way also, but I don't know what you are actually doing with that odd date format, so this at least answers your actual question, I think.

Cromicon’s picture

Thanks, that's got me a bit further I think, now I'm just getting the unexpected t string error on the line containing the first instance of $ycyear - and I can't spot a missing ; anywhere.

    $year = date('Y', $node->created);
    $month = date(‘m’, $node->created);
    $day = date(‘d’, $node->created);
    $ycyear = $year – 1898;
    $date = "YC-" .$ycyear. "-" .$month. "-" .$day;
    print "Transmitted by ". theme('username' . $node) . " | " . $date; 
mshepherd’s picture

while type casting ought not be a problem, you could try casting the $year as an integer with:

    $year = date('Y', $node->created);
    $year=(int)$year;
    $month = date(‘m’, $node->created);
    $day = date(‘d’, $node->created);
    $ycyear = $year – 1898;
    $date = "YC-" .$ycyear. "-" .$month. "-" .$day;
    print "Transmitted by ". theme('username' . $node) . " | " . $date;
dman’s picture

The code you pasted there had "smart" quotes - which would cause dodgy syntax errors, so I'd suggest using a text editor - not Microsoft Word - to edit your PHP files.

mshepherd’s picture

Good point. Look at your code. Sometimes, you have proper single quotes (date('Y'...) and sometimes smart quotes (date(‘m’...). Make sure to only use single quotes. If you use any decent text editor, this is easy, but many word processors will try to add smart or typoghraphers quotes.

<?php
    $year = date('Y', $node->created);
    $month = date('m', $node->created);
    $day = date('d', $node->created);
    $ycyear = $year – 1898;
    $date = "YC-" .$ycyear. "-" .$month. "-" .$day;
    print "Transmitted by ". theme('username' . $node) . " | " . $date;
?>
Cromicon’s picture

Brilliant thank you.

Well, for posterity this worked:

    $year = date('Y', $node->created);
	$year=(int)$year;
    $month = date('m', $node->created);
    $day = date('d', $node->created);
    $ycyear = $year-1898;
    $date = "YC-" .$ycyear. "-" .$month. "-" .$day;
    print "Transmitted by ". $name . " | " . $date;

Replacing the print $submitted in node.tpl.php with the above code allowed the display of the date to become the Eve Online format obeying the Yoiul Conference calendar guidelines.
Further info here:
http://wiki.eveonline.com/en/wiki/YC

For the record, I do use notepad++ but it seemed that areas I was copying code from had those confounded smart quotes. Eliminating them was not the issue though as the error remained. I deleted the spaces here: $year-1898; and that resolved - they must have had odd character coding in there.

So thank you to everyone for their patient assistance!

mshepherd’s picture

No problem. Glad you got it sorted.
Looking at the code in your previous post, it looks like that '-' symbol was an en-dash rather than a -