Convert a string in a date

i have a string dat1="01/01/01/"
i want to convert it to a date (type Date)
do so know how to do ?????
please help
thanks for all

Please don't crosspost. It cuts down on the effectiveness of responses, leads to people wasting their time answering what others have already answered, makes for difficult discussion, and is generally just annoying and bad form.

Similar Messages

  • How to convert a string value to date

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    In your post you ask how to convert a string value to a date.  The value returned from the Get-AdUser is already a date.  It does not need to be converted.
    Bill has sshown one way to convert a date to a string and there are other methods.  You need to clarify your question.
    If you are really trying ot convert strings to dates then you can start with this:
    [datetime]'01/21/1965 13:33:23'
    Most date strings aer autodetected by the class.
    ¯\_(ツ)_/¯

  • Error in converting character string to smalldatetime data type

    I've installed SQL Server 2000 on my new laptop and Crystal Report XI, out of sudden, the Crystal Report to certain view can't run and I got the following error:
    Details: 22007 [Microsoft][ODBC SQL Server Driver][SQL SERVER]Syntax Error cnverting character string to smalldatetime data type.
    Any suggestions?
    Hannah

    Here is the view the err is complaining about:
    SELECT     TOP 100 PERCENT Cur.Closed_Month, Cur.Closed_Year, Cur.Incidents_Closed, Prev.Incidents_Closed AS PrevIncidents_Closed,
                          YrAgo.Incidents_Closed AS YearIncidents_Closed
    FROM         (SELECT     Closed_Month, Closed_Year, Incidents_Closed
                           FROM          dbo.Incidents_Closed) Cur INNER JOIN
                              (SELECT     Month(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevMonth,
                                                       year(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) Prev ON Cur.Closed_Month = Prev.PrevMonth AND Cur.Closed_Year = Prev.PrevYear INNER JOIN
                              (SELECT     Month(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevMonth,
                                                       year(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) YrAgo ON Cur.Closed_Month = YrAgo.PrevMonth AND Cur.Closed_Year = YrAgo.PrevYear
    What confused me is that it works fine with my previous laptop. I wonder if there is any patch in Crystal Report or SQL server that used to support certain functions but not support them anymore....
    Thanks
    Hannah

  • How to convert a string into orcle date format

    i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.

    Here's some code to help. I can't remember what method uses what format though
      public static java.sql.Date sqlDateValueOf( String dateString ) {
        String stringDate = null;
        if ( dateString == null || dateString.length() < 10 ) return null;
        String strDay = "";
        String strMonth = "";
        String strYear = "";
        if ( dateString.substring(4,5).equals( "-" ) ) {
          strDay = dateString.substring(8, 10);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(5, 7);
          strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(0, 4);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        else if ( dateString.substring(2,3).equals( "-" ) ) {
          strDay = dateString.substring(0, 2);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(3, 5);
          strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(6, 10);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        Calendar cal = Calendar.getInstance();
        cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
        cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
        cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
        java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
        return outDate;
      public static String toDateString( java.util.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date, String format) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat( format );
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Timestamp date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      }

  • Converting 3 Strings to 1 Date?

    Hi first of i am very new at this sql. But my problem is that i am haveing 3 combo boxes in java. 1 with dd 1 with mm and 1 with yyyy. How do i convert these 3 strings into 1 date format? Writing the Gui in java.
    It is to a booking system so i need it for a fromdate and then the same in a todate function. Hope u understand my problem.
    Best regards
    Jakob

    take care of 1 digit days/months. (ex 31-2 != 3-12). So if you have digits, you could use to_date(d||'.'||m||'.'||y,'DD.MM.YYYY)Message was edited by:
    Laurent Schneider
    31-2 very clever example ! Sorry about that...

  • Converting a string into mySQL date format

    I have a bit of code that collects data values from a bean and I want it to then insert this into a mySQL database. My string is in the format "23/12/1983", how can i put this into a date field in my database? The bit of code I have got so far looks like this...
    String month = formHandler.month + "/";
    String day = formHandler.day + "/";
    String year = formHandler.year ;
    StringBuffer sb = new StringBuffer();
    sb.append(day);
    sb.append(month);
    sb.append(year);
    String myDate = sb.toString();myDate is the value that I want to go into the database

    Limo2kz,
    The key to inserting a date into a database is to convert the date string into an SQL friendly format. i.e. yyyy-MM-dd.
    One way of doing this is as follows:
    SimpleDateFormat NICE_DATE_FORMAT =
    new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat SQL_DATE_FORMAT =
    new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    try {
    date = NICE_DATE_FORMAT.parse(dateString);
    } catch (ParseException pe) {
    pe.printStackTrace();
    String sqlDate = SQL_DATE_FORMAT.format(date);
    Now it is just a matter of creating the insert statement like normal, and making sure that the date string is in quotes.
    I hope that helps.
    Damian Sutton

  • Convert a string to a Date

    I have a string object.
    String s = "2006-12-26 17:33:36"
    How can I create a date object from that string?
    I tried Date date = new Date(s);
    But that looks like a deprecated method. What is the best way ?
    Im using mysql db and their the type of the column is datetime. But I can store their if I can convert to Date type. Can you help me.
    thanks in advance..

    Look at the parse() method of thge SimpleDateFormat class. In the javadoc, it says this;
    parse
    public Date parse(String text, ParsePosition pos)
    Parses text from a string to produce a Date.
    The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed date is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.

  • How to convert a String into a date in yyyy-MM-dd using SimpleDateFormat?

    Hi Guys,
    I am using the following code
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class ValiDATE {
         private static boolean validateDateFormat(String strDate) {
              try {
                   SimpleDateFormat formatter = new SimpleDateFormat("yy-MM-dd");
                   try {
                        formatter.setLenient(false);
                        formatter.parse(strDate);
                   catch (ParseException e) {
                        // invalid date/datetime format          
                        return false;
              catch (Exception ignored) {
              return true;
         public static void main(String args[]){
              System.out.println(validateDateFormat("11111-11-11"));          
    }In the above snippet even if I pass the string parameter as "11111-11-11" it returns a new date and hence prints TRUE in the console, but I want the date to be in yyyy-MM-dd format that is no of years shouldn't exceed 4 digits in all.
    I don't want to use RegEx, I know this can be done using SimpleDateFormat, but would like to know how that can be done.
    I think it has to do something with this . ( [http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html#year|http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html#year] )
    Regards
    AR

    Java.slogger wrote:
    Yeah I have gone through the javaDoc and it says For formatting, if the number of pattern letters is 2, the year is truncated to 2 digits; otherwise it is interpreted as a number. The important part is:
    JavaDoc:
    Any other numeric string, such as a one digit string, a three or more digit string, or a two digit string that isn't all digits (for example, "-1"), is interpreted literally.
    Do you know any workarounds else is using a Regex is the best approach?I don't see this as a problem. Everything behaves as designed and as is sensible.
    So if you want to avoid dates with 5-digit numbers, I'd add something like:
    if (parsedDate.after(CUTOFF_DATE)) {
      throw new OhNoesThisIsEvilException("!");
    }

  • Converting the string value to data format

    Hello Everyone,
                                  Please guide me in converting the value to date format.
    from source i'm getting the value (which is acchally a data value) '20070730'.
    I need this value to be in date format '2007/07/30'
    Please help me in getting it done.
    thank you

    Hi
    Code Snippetselect cast('20070730' as datetime)
    Note : beware of collation used in your SQL instance or your database.
    Jean-Pierre

  • How to convert a string to a Date obj ?

    Hi,
    String xx; "xx is from a table rs.getString();"
    Date dd = Date.valueOf(xx);
    id = today.compareTo(dd);
    Complier complains , why ?
    Thanks in advance.
    Philip

    Hi,
    I finally figured the reason. I have to put "java.sql.DatevalueOf( )" in the code. I guess there are 2 Date classes. One is in the Util.* and the other in sql.*...
    The one in Util.* means something else...
    Thanks anyway.
    Philip

  • How to convert a String("yyyy-mm-dd") to the same but in Date format ?

    Hi,
    can anyone plz tell me how to convert a String to a date format.I'm using MSACCESS database.I want to store this string in the database.So i need to convert it to a date format since the table is designed such a way with date/time type for date field.I used SimpleDateFormat ,but i can't able to convert.The code is given below:
    coding:
    public String dateconvertion(String strDate)
    try
    SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdfSource.parse(strDate);
    SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd ");
    strDate = sdfDestination.format(date);
    catch(ParseException pe)
    System.out.println("Parse Exception : " + pe);
    return(strDate);
    }

    i used prepared statement even now i am getting error like this.....
    i have included the prepared statement package also...
    my coding:
    ResultSet rsdatetemp = null;
    PreparedStatement ps = null;
    String query ="select distinct itemcode from sales where bill date between ? and ?";
    ps = precon.prepareStatement(query);
    ps.setDate(1,d1);//d1 and d2 are in date format
    ps.setDate(2,d2);
    rsdatetemp = ps.executeQuery();
    error :
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(1,d1);
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(2,d2);

  • Converting a java string to a date.

    I am working on extending an EO and I have a situation where I must convert a string to a date before passing it to a method. The string is in the format "DD-MON-YYYY". I am using the following code and get an error "incompatible types: found: java.util.Date, required: oracle.jbo.domain.Date". Here is the code I am using:
    try {
    SimpleDateFormat df=new SimpleDateFormat("DD-MON-YYYY");
    oracle.jbo.domain.Date expdate=df.parse(expendituredate);
    setExpenditureItemDate(expdate);
    catch (Exception err) {
    Any ideas why the code I am using is not working? Is there another way to do this?
    Mike

    The difference is that
    D Day in year
    d      Day in month
    Hence when you used 22-Feb-2007 with "DD-MMM-yyyy", it took 22 as the 22nd day of the year and overrided the month value giving you 22nd January :)
    Cheers
    --Saroj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Converting a String to Date

    I have a String in which i am storing the date which I have retrieved from database. How can I convert this String to a Date object and use Comparator for sorting.
    String strCreatedDate1 = ((CVendorEmployees) vendoremployee1).getCreatedDate().toUpperCase();The date format which I will retrieve from String is mm/dd/yyyy.
    I want to convert this into date and use it for sorting.
    Thanx.

    Date dtTmp = new
    SimpleDateFormat("dd-MM-yyyy").parse(((CVendorEmployee
    s) vendoremployee1).getCreatedDate());
                                  Calendar calendar = Calendar.getInstance();      
                                  calendar.setTime(dtTmp);
    Now you have the date object do what ever you wish toBetter make thatnew SimpleDateFormat("MM/dd/yyyy")And no need for the Calendar stuff if all you want is a Date object.

  • How to convert a string

    I have a string "March 2006", that I would like to convert into two dates, one is first date of the month and second is the last date of the month.
    For example:
    String strDate="March 2006"
    Now I want to convert it into two dates:
    03/01/2006 and 03/31/2006 and assign those two dates to two variables.
    I have been trying something like this just to convert string to date but no luck:
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         java.util.Date mydate = new java.util.Date();
         try{
         mydate = sdf.parse("March 2006");
         }catch(ParseException e){}
         System.out.println("Java data object is"+mydate);
    I get following output : Tue Jun 20 10:34:30 CDT 2006

    Thanks for your patience guys. First I am not a java
    expert and just a new bee to Java, and second I guess
    we are going into a different direction here. My
    basic problem is that is there a way to convert
    "March 2006" string to 03/2006? Then once we get
    03/2006, can we find what is the first date ,
    offcourse 01, and what is the last date, which in
    this case is 31?Convert the String to a Date, as you've already been shown how to do
    Use the java.util.Calendar methods to get your last day of the month value (check the javadoc, especially the get method and look at the fields) Post back with any specific questions.
    Good Luck
    Lee
    >
    For example:
    My variable is "March 2006". The end product I want
    is:
    strDate1=03/01/2006
    strDate2=03/31/2006.
    How should I get my end product?
    I can write string manipulation functions to get this
    done,but trying to see if there is an easiest way to
    do this. Thanks.

  • String object to Date object

    Hi,
    I have date as string object "22/04/2008". I want convert this string object to Date object as specified format (dd/MM/yyyy) only.
    Please do the need full.
    Thanks in Advance

    kishoreyakkali wrote:
    Hi,
    I tried as follows
    SimpleDateFormat strOutDt = new SimpleDateFormat("dd/MM/yyyy");
    Date dateObj=strOutDt.parse(strTmp);
    System.out.println("dateObj::::" + dateObj);
    Output : Mon Apr 21 00:00:00 IST 2008 A date object is always a wrapper around a millisecond value. It does not contain any formatting information, so you should never print a Date object. You should always convert it to a String using SimpleDateFormat before you print.
    Kaj

Maybe you are looking for

  • Shipping and delivery status from R/3 to CRM

    Hi all, we are creating sales orders in CRM and replicating it to R/3. CRM is the owner of the document. Now whenever changes are done to sales order in CRM, the changes are replicated to R/3. Let's say the shipping status is updated in R/3. Now the

  • Can't migrate from Leopard to Lion

    My target mac (lion) says that I need to update my Migration Assistant in  my source mac (leopard).  I did so, but it is already the latest version.  The source mac does not detect the target mac either.  Is this a bug in Lion that it cannot detect L

  • Call report selection screen in module pool program with tab strip control

    Hi, Could anyone explain in detail to call report selection screen in module pool program with tab strip control. Thanks Mano

  • Skinning Flash CS3 component

    I posted this in General but haven't gotten a reply, and now I'm beginning to wonder if this must be accomplised with ActionScript. It's great that you can double click a component, open it up, and put your own artwork right in there and set the 9-sl

  • Sql loader error in offline data load

    Hi, I have done an offline schema creation using existing tablespace. I am trying to do an offline data load using sql loader.The CTL and DAT file are generated by the work bench. This is my CTL file code generated by workbench. load data infile 'Imp