Link to home
Start Free TrialLog in
Avatar of jonnyfb
jonnyfb

asked on

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
Avatar of browolf
browolf

Hi jonnyfb,

what languages can u use on the server? ASP/php/something else?
is the field in the database a date field?
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];
?>


Avatar of jonnyfb

ASKER

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)
ASKER CERTIFIED SOLUTION
Avatar of dc_cypher
dc_cypher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonnyfb

ASKER

ok ill try it

ps. Quick answer thanks!
Avatar of jonnyfb

ASKER

ok that works! Thanks! Split is really useful!
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