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
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
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];
?>
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];
?>
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)
(eg. i need to get 2004 out of 05/08/2004 10:26:23)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok ill try it
ps. Quick answer thanks!
ps. Quick answer thanks!
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
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
what languages can u use on the server? ASP/php/something else?
is the field in the database a date field?