Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

extract the year from a full date string

Posted on 2004-11-07
7
Medium Priority
?
259 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:jonnyfb
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:browolf
ID: 12517514
Hi jonnyfb,

what languages can u use on the server? ASP/php/something else?
is the field in the database a date field?
0
 
LVL 1

Expert Comment

by:dc_cypher
ID: 12517556
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
 
LVL 1

Author Comment

by:jonnyfb
ID: 12517874
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Accepted Solution

by:
dc_cypher earned 80 total points
ID: 12517889
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
 
LVL 1

Author Comment

by:jonnyfb
ID: 12517900
ok ill try it

ps. Quick answer thanks!
0
 
LVL 1

Author Comment

by:jonnyfb
ID: 12517939
ok that works! Thanks! Split is really useful!
0
 
LVL 3

Expert Comment

by:browolf
ID: 12518581
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question