extract the year from a full date string

in my data base i have a field which contains the date that the user joined. once i have taken that out of the database i want to create a new string which is the year from the other value. how would i do that.

ps. i only need to know how to do this

date user joined - 05/08/2004 10:26:23
from that  ^ get this: year user joined - 2004
LVL 1
jonnyfbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

browolfCommented:
Hi jonnyfb,

what languages can u use on the server? ASP/php/something else?
is the field in the database a date field?
0
dc_cypherCommented:
If you're extracting the date from the database, you can grab the year value at that time in many databases.

MySQL example:

SELECT YEAR(Date_Field) FROM My_Table

If you're relegated to performing it in your script, however, this is how you could do it in PHP:

<?php
$my_date = '05/08/2004 10:26:23';

// divide date up into date and time
$arrDateTime = explode(' ', $my_date);

// divide date into component parts
$arrDate = explode('/', $arrDateTime[0]);

// display year
print $arrDate[2];
?>


0
jonnyfbAuthor Commented:
im using ASP and i dont need help gettin the value out of the database. i need to seperate the year from a full date
(eg. i need to get 2004 out of 05/08/2004 10:26:23)
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

dc_cypherCommented:
You should be able to do the same thing I described in php (note: this is untested code).

<%
my_date = "05/08/2004 10:26:23"

' divide date up into date and time
arrDateTime = split(my_date, " ")

' divide date into component parts
arrDate = split(arrDateTime(0), "/")

' display year
Response.Write arrDate(2)
%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jonnyfbAuthor Commented:
ok ill try it

ps. Quick answer thanks!
0
jonnyfbAuthor Commented:
ok that works! Thanks! Split is really useful!
0
browolfCommented:
asp and wsh both use vbscript as their core language.

check out the vbscript language reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp

especially the function list,  knowing what built in functions  exist  even if you dont know how to use them is pretty darn handy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.