Click to See Complete Forum and Search --> : php getdate()


minus18
09-17-2001, 03:35 PM
Can anyone give me advice on using this function?

I have a date in mySQL format, extracted from a database.

so
echo "$lowYear";

gives: 1999-01-01.

I want to extract the 1999 bit and ignore the rest and I can't for the life of me do this.

Any ideas?
:confused:

Raskii
09-17-2001, 05:18 PM
You should be able to simply read the first 4 characters out of the variable. Not sure how to do this off the top of my head though.

element-x
09-17-2001, 06:57 PM
I believe it would be ...

$year = substr($lowYear,1,4);

Assuming that you always wanted the first 4 characters of the variable.

element-x
09-17-2001, 06:59 PM
Second note:

for quick php reference, check out
http://www.php.net/quickref.php

If you have an idea of what the name of a function might be, you can easily look it up on that page and on top of getting the proper syntax, you get an example (from whoever wrote the docs) plus any extra notes left by users.

I find it to be a great reference, I hope it helps you out aswell.

Salmon
09-17-2001, 09:34 PM
You can also let MySQL do the work for you by using the DATE_FORMAT function in your query . . .


$sql = "SELECT DATE_FORMAT(date_column, '%Y') AS year FROM your_table";


The results of the query will then have a 'year' column ready to use.

minus18
09-18-2001, 03:19 AM
It was:

$year = substr($lowYear,0,4);

Cheers all for your help. I knew LNO would come to my rescue.

element-x
09-18-2001, 04:23 PM
Salmon, my main man!
Thanks, that SELECT Query is lovely!

It just made my day entirely great. :D

Salmon
09-19-2001, 04:11 PM
Salmon, my main man!
Thanks, that SELECT Query is lovely!


I'm glad you found it useful. ;)