[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to break a java String into three differnt Strings

Posted on 2006-04-10
3
Medium Priority
?
161 Views
Last Modified: 2010-04-01
I am getting date as a parameter in this format 20060924. What I need is to seperate the day mmonth and year from this String.
It will always be in this format.

Any help will be greatly appeciated

0
Comment
Question by:royalcyber
  • 2
3 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 16423470
You can etiher use substring or DateFormat.

    String date = "20060924";
    String year = date.substring(0, 4);
    String month = date.substring(4, 6);
    String day = date.substring(6, 8);


    DateFormat df = new SimpleDateFormat("yyyyMMdd");
    Calendar cal = Calendar.getInstance();
    cal.setTime(df.parse("20060924"));
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
0
 

Author Comment

by:royalcyber
ID: 16427720
Thankyou boonleg for your prompt response. I was actually trying to compare the date which i get as a request parameter to the date/time field in MSSQL,
would you know how would I be able to do that. I am getting the date in this format date = "20060924"; Thanks
0
 
LVL 14

Accepted Solution

by:
boonleng earned 500 total points
ID: 16435352
Use use DateFormat to parse string to date object and use date.compareTo(anotherDate) to compare the date retrieve rom database.

DateFormat df = new SimpleDateFormat("yyyyMMdd");
Date date = df.parse("20060924");
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 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