Convert string to  calendar

bail me out of this problem
i got 3 "Calendar" objects : "to" , "from" and "now"
i got another Sting Object "n"
where String n = now.toString()
I have access to "to", "from" and "n"
and I have to know whether n lies in between "to" and "from"
The following code does not give right answer
if(from.before(n) && to.after(n))
System.out.println("n lies between to and from");
help me out...

Create a suitable SimpleDateFormat object and use it to convert your string to a java.util.Date before making the test.
You probably want Date objects, not Calendar objects. Calendar objects are for doing date calculations - like adding a month to a date or whatever.

Similar Messages

  • Converting String to Calendar Object

    Hi,
    I nedd to Change the below String to Calendar Object.i want to show the records which are older than half an hour.any other idea which will solve my problems?
    Fri Aug 17 01:56:40 GMT+05:30 1906
    Thanks in advance.
    Regards:
    Akash.

    Look at
    java.text.SimpleDataFormat

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • Converting a String to Calendar

    I have a String which is actually a date in the format yyyyMMdd.
    I need to take this String and convert it into a Calendar to do a before() check.
    I want to delete dates prior to a certain date.
    I am able to use this code to get a String to a Date but I need a String to a Calendar.
    String sDateOfDir = null;
    sDateOfDir = children;                              
    Date dStringToDate = (Date)sdf.parse(sDateOfDir);      
    Calendar cal = Calendar.getInstance();
    cal.setTime(dStringToDate); // this is still java.util.Date
    I need a String to a Calendar
    or
    can this line of code
    cal.setTime(dStringToDate); be formatted to yyyyMMdd
    any suggestions thanks in advance

    I dont know what I am having such a block today. I am not sure I understand. I have posted my code and I hope you can just point out how I can make this easier.
    I am reading in a File Directory with its subfolders.
    The subdirs are named with the Date the subdir is created (yyyyMMdd)
    I want to delete the subdirs that are older than 30days
    public class RemoveFileFolders
         public static String sDirDNE = "Either dir DNE or is not a dir";
         public static String sSuccessFalse = "!success false";
         public static String sNowDeleting = "Now deleting contents of ";
         public static String sForSub = " for subdir(s) prior to ";
         public static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
         public static void main(String[] args)
              File fDir = new File("\\C:\\Dates");
              Calendar cTodayMinusOneMonth = Calendar.getInstance(); //today
              cTodayMinusOneMonth.roll(Calendar.MONTH, false); //today minus one (1) month
              //I want to delete all subdir that are older than 20070821
              System.out.println(sNowDeleting + fDir + sForSub + sdf.format(cTodayMinusOneMonth.getTime()));
              //String sCalToString = null;
              //sCalToString = sdf.format(cTodayMinusOneMonth.getTime()).toString();
              if(fDir.isDirectory())
                   String[] children = fDir.list();     
                   if (children == null)
                        System.out.println(sDirDNE);
                   else
                        try
                             for (int i = 0; i < children.length; i++)
                                  String sDateOfDir = null;
                                  sDateOfDir = children;
                                  Date dStringToDate = (Date)sdf.parse(sDateOfDir);
                                  System.out.println("sDateOfDir I am a string " + sDateOfDir);
                                  Calendar cal = Calendar.getInstance();
                                  //cal.setTime(dStringToDate);
                                  cal.before(dStringToDate);
                                  //if DateDir is before cTodayMinusOneMonth.roll(Calendar.MONTH, false); //today minus one (1) month
                                  //delete that dir
                                  if(children[i].equalsIgnoreCase(sDateOfDir))
                                       boolean success = deleteDir(new File(fDir, children[i]));
                                       if (!success)
                                            System.out.println(sSuccessFalse);
                        catch(ParseException pe)
                             System.out.println("ParseException " + pe);
         public static boolean deleteDir(File fDir)
              if (fDir.isDirectory())
                   String[] children = fDir.list();
                   for (int i = 0; i < children.length; i++)
                        boolean success = deleteDir(new File(fDir, children[i]));
                        if (!success)
                             return false;
              return fDir.delete();

  • How to convert a String to Calendar ?

    Hello all,
    I need to convert a date which is in the form dd-mon-yyyy to a Calendar. Can any one help me ?. This is my first post here.

    And an example:import java.text.*;
    import java.util.*;
    public class Test {
        public static void main (String[] parameters) {
            try {
                System.out.println (getDate (getCalendar ("17 jun 2003", "dd MMM yyyy"), "d MMMM yyyy"));
            } catch (ParseException exception) {
                exception.printStackTrace (System.err);
                System.exit (- 1);
        private static Calendar getCalendar (String date, String format) throws ParseException {
            Calendar calendar = new GregorianCalendar ();
            calendar.setTime (new SimpleDateFormat (format).parse (date));
            return calendar;
        private static String getDate (Calendar calendar, String format) {
            return new SimpleDateFormat (format).format (calendar.getTime ());
    }Kind regards,
      Levi

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting String To XML Format and send as attachment

    Hi
    My requirement is to convert String into XML Format and that XML File i have to send as an attachment
    can any one one give solution for this Problem.
    Thank you
    Venkatesh.K

    hi,
    i m filling the itab first and converting to xml
    itab contaning these data
    GS_PERSON-CUST_ID   = '3'.
    GS_PERSON-FIRSTNAME = 'Bill'.
    GS_PERSON-LASTNAME  = 'Gates'.
    APPEND GS_PERSON TO GT_PERSON.
    GS_PERSON-CUST_ID   = '4'.
    GS_PERSON-FIRSTNAME = 'Frodo'.
    GS_PERSON-LASTNAME  = 'Baggins'.
    APPEND GS_PERSON TO GT_PERSON.
    after conversion data is coming like that
    #<?xml version="1.0" encoding="utf-16"?>
    <CUSTOMERS>
      <item>
        <customer_id>0003</customer_id>
        <first_name>Bill</first_name>
        <last_name>Gates</last_name>
      </item>
      <item>
        <customer_id>0004</customer_id>
        <first_name>Frodo</first_name>
        <last_name>Baggins</last_name>
      </item>
    </CUSTOMERS>
    but errors are  1) # is coming at the first
                            2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
    can anybody plz solve it.
    regards,
    viki

  • Converting string to XML format

    Hi All,
    I have a requirement to convert string to xml format and download it. Atpresent, I have a string which is a collection of xml tags. I want to convert this string to xml format like <VALUE004>20387899.437</VALUE004>
    <VALUE005>20387899.437</VALUE005>
    <VALUE006>20387899.437</VALUE006>
    Is there any function module for this.

    Chk this thread.
    Re: Regd: File Conversion to XML format

  • Converting string to xml in xslt

    Hi we are trying to convert string to xml in xslt but it is getting errored out.
    We have followed the procedure mentioned at http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a88894/adx04xsl.htm under the section "How Do I Convert A String to a Nodeset in XSL?".
    Standard procedure mentioned by oracle is not working. Is it a known bug?

    Chk this thread.
    Re: Regd: File Conversion to XML format

  • Converting string(which is an xml from the java side) to xml in flex

    Hi,
       I have an xml from the java side which i send as string over amf. I need to convert this to xmllist or xml and bind it to a tree. Could some one help me in doing this. My label field needs to be displayName
    this is my xml that comes as string to the flex side
    <Menu>
      <MenuItem>
        <id>1</id>
        <displayName>Add</displayName>
        <menuList>
          <MenuItem>
            <id>3</id>
            <displayName>Form1</displayName>
            <menuList/>
          </MenuItem>
          <MenuItem>
            <id>4</id>
            <displayName>Form2</displayName>
            <menuList/>
          </MenuItem>
        </menuList>
      </MenuItem>
      <MenuItem>
        <id>2</id>
        <displayName>Delete</displayName>
        <menuList>
          <MenuItem>
            <id>5</id>
            <displayName>Form1</displayName>
            <menuList/>
          </MenuItem>
          <MenuItem>
            <id>6</id>
            <displayName>Form2</displayName>
            <menuList/>
          </MenuItem>
        </menuList>
      </MenuItem>
    </Menu>

    Well, for Binding you will probably need to further convert to XMLListCollection or ArrayCollection.
    Not sure.
    However, that is the way to convert String to XML.

Maybe you are looking for

  • Filter value for variable selection screen

    Hi & help !, This could be a tricky or an easy question, but it seems too hard for me ! I'm storing version in my cube, and have a report which shows informations for the version you select (with a variable = ZVERSION01). ex :  Version : V01 V02 V03

  • How to edit .mov files?

    I installed premiere cs4 on my pc. When I imported some .mov files into the project, I can preview the video clips but without sound. I installed the sound card driver correctly and can play mp3 files normally. anyone gave some tips?

  • Problem seeking video in flash player 9,0,115,0

    Hi all, I had a flash app that loads and plays an FLV, when it reaches the end it seeks to a point in the middle of the video and loops that. This had been working fine for ages, but now with the latest flash player update, there is a bug in the seek

  • IPAd2 not recognised in iTunes. Tried restore get - unknown error (1621).

    iPAd2 not recognised in iTunes. Tried to restore but get - unknown error (1621). Unable to update iTunes to latest. Tried everything else but no change. Any suggestions?

  • Family Apple id and messaging/FaceTime

    I have just bought an iMac (my daughters both have iPads and iPods). After initially using our shared Apple id and getting all their message & FaceTime requests popping up, I created my own Apple id and switched the iMac login and preferences to it,