Conversion String to Date
How can I convert a string like YEAR,WEEK OF THE YEAR, DAY OF
THE WEEK to YEAR,MONTH,DAY???
I can do this :
SELECT SYSDATE, TO_CHAR(SYSDATE,'YYYYWWD') FROM DUAL;
SYSDATE TO_CHAR
07-DEC-01 2001496
But i need the inverse
Help
Thanks
Cleber
I'm not sure if this is the most elegant solution, but it seems
to work.
SQL> CREATE OR REPLACE FUNCTION get_date_week
2 (v_string IN VARCHAR2)
3 RETURN DATE AS
4
5 v_first_day DATE := TO_DATE('01-JAN-' || SUBSTR
(v_string,1,4));
6 v_date_week DATE;
7 v_date_char VARCHAR2(20);
8
9 BEGIN
10 FOR i IN 0..365
11 LOOP
12
13 v_date_week := TO_DATE(v_first_day + i);
14 v_date_char := TO_CHAR(v_date_week, 'YYYYWWD');
15
16 IF v_date_char = v_string
17 THEN RETURN v_date_week;
18 END IF;
19
20 END LOOP;
21 END;
22 /
Function created.
SQL> SELECT get_date_week('2001496')
2 FROM dual
3 /
GET_DATE_
07-DEC-01
SQL> SELECT get_date_week('2001496')
2 FROM dual
3 /
GET_DATE_
07-DEC-01
SQL> SELECT get_date_week('2001497')
2 FROM dual
3 /
GET_DATE_
08-DEC-01
Similar Messages
-
Regarding conversion of String to Date
Hi
Ravi here and I am getting the following exception when i am working with String to date conversion.As i am working in LAN this code is working for all others .This problem is with my system only.This is not supporting with yyyy-MM-dd format.One more thing in my system only we installed VisualStudio.Is that a problem for this exception.I am using Myeclipse
Plzzzzzzzzzzz help me I got strucked .
Thanks in advance
Code:
public void testSaveDates() throws HibernateException, ParseException{
try{
Date date=new Date();
String str1 ="2006-05-06";
Date dateFormatter = new SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;
System.out.println(dateFormatter);
catch(Exception e){
e.printStackTrace();
Exception:
java.text.ParseException: Unparseable date: "2006-05-06"
at java.text.DateFormat.parse(DateFormat.java:335)
at chaitanya.MyTest.testSaveDates(MyTest.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)Date date=new Date();You don't need this line.
Date dateFormatter = new
er = new
SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;As already told, you don't need the single quotes. And you don't need two semi-colons - that's unnecessary.
I just wrote a sample code to test that out. Check it and see for yourself.
import java.text.SimpleDateFormat;
public class Test {
public static void main(String[] args) throws Exception {
System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2005-04-18"));
System.out.println(new SimpleDateFormat("'yyyy'-'MM'-'dd'").parse("2005-04-18"));
}Output:
Mon Apr 18 00:00:00 EDT 2005
Exception in thread "main" java.text.ParseException: Unparseable date: "2005-04-18"
at java.text.DateFormat.parse(DateFormat.java:335)
at Test.main(Test.java:6)I wonder why it is not feasible to write a quick sample code. -
i have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion.
i wrote the method but it not workig
My method is
-(NSDate *)dateformstr:(NSString *)str
NSString *date = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
[dateFormate setDateFormat:@"yyyy-MM-dd'T'HH:mm:sssZZZZ"]
// NSDate *formatterDate = [dateFormate dateFromString:str];
return formatterDate;
but i did not the value and if i try othere formate i is working but my requiremet format is 2012-04-30T23:48:55.727-07:00.
can any help it out in this senario.Sorry Butterbean, but I'm interested in the answer to your question myself.
I've spent a few hours transfering my library from one computer to another and then find out that my ratings didn't transfer. Like you, I've spent many hours rating my 2000+ songs. I'm sure you have more, nevertheless, I want to find out how to get those ratings. They still show in my iTunes on my laptop but, when I go to the iTunes folder and display the details of at song, no rating is there. If you find out how to get them to display there in the iTunes folder, it seems that would be the key.
Hope you get your answer soon. -
Can anyone tell how to convert a String into date??
if the string is in the format "Thu Mar 25 17:11:34 GMT+05:30 2004"
i have converted it. code is
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
Date date = null;
try
//date = dateFormat.parse(new Date().toString());
date = dateFormat.parse(dateLine);
catch(ParseException ex)
but i am not able to specify the year.
so when i getYear on the new Date it return 1970.@duffymo, I'm pretty sure "d" is good for a two digit date, "dd" gives you zero-padding.
The problem, presumably, is that the format string "EEE MMM d yyyy HH:mm:ss" does not match the actual format "Thu Mar 25 17:11:34 GMT+05:30 2004".
The correct format string would be "EEE MMM d HH:mm:ss z yyyy" -
String to DATS format conversion in XI.
Hello Experts,
I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
Please Help!!!!Lokesh,
With XI there is a date transformation function under date category there you need to provide source date format and target date format..
I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
Regards, -
String to DATS format Conversion
Hello Experts,
I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
Please Help!!!!Lokesh,
With XI there is a date transformation function under date category there you need to provide source date format and target date format..
I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
Regards, -
String to date conversion problem
Hai braniees,
i am new to java.I have a problem in converting string to date.my code is this
dob="2/05/2005";
SimpleDateFormat sf=new SimpleDateFormat("dd/MM/yyyy");
Date dt=sf.parse(dob);
i this i am getting the error in the last line.the error is
" Unhandled exception type ParseException"
I am not able to getrid of this.
Thanks
anieshukI would advise against doing what ranjithcp suggested unless you are such a perfect programmer that you'll never get invalid data into your methods. Also what ranjithcp has failed to mention is that you'll have to put the throws instruction all over your code right up to your main method otherwise your just moving your error message up through your program.
You should always try and handle checked exceptions not throw them. -
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 CollierYou 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. -
Problem in Converting String to Date
Hi All,
I am having one String
String date = "2006-01-17 15:19:57.0"
I want to parse this String into Date object.
I will really appriciate if somebody helps me out.
Thanks.You're specifying a 'T' and a timezone in your format, but they're not present in the string you're parsing.
I'm assuming from the way you're printing out the date, that your thinking is along these lines: "sdfInput will parse the input string, no matter what format it's in, and will produce a Date object. That Date object wil have the format specified in sdfInput."
This is wrong on a couple of fronts:
1) DateFormat doesn't magically figure out what format it's supposed to use for the String it's parse()ing. The String has to match the DF's format.
2) Dates don't have formats. Only Strings do. A Date object is just a long. There's no relationship whatsoever between the Date that you get from parse() and the format that was used to produce it. When you print out a Date as you're doing, its toString method is called, which in turn uses a default format for your Locale.
If you want to turn a date string in one format into a date string in another format, use two different DateFormat objects with two different formats. Date date = df1.parse(inputString);
String outputString = df2.format(date); -
Facing Problem in parsing a string to date
Hi,
I was trying to change a string into date with date format ("EEEE,MMM,d,h:mm") but I always get the year as 1970.
here is my code
String strDate="Saturday,Jan 19 7:31";
String dateFormat3="EEEE,MMM,d,h:mm";
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat3);
result1=myDateFormat.parse(strDate);
catch(ParseException pe) {
System.out.println("ERROR: could not parse date in string \"" +
}any solution for it.This is my actual code
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TestingDate {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
String dateFormat="EEEE, MMM d h:mm a";
Date test=new Date(2007,0,19, 19, 31);
System.out.println(" original date is "+test);
String stringResult=DateToString(test,dateFormat);
System.out.println("Date to string is "+stringResult);
Date dateResult=stringToDate(stringResult,dateFormat);
System.out.println(" String to date is "+dateResult);
String stringResult2=DateToString(dateResult,dateFormat);
System.out.println(" Date to string is "+stringResult2);
public static String DateToString(Date test, String dateFormat) {
String result = null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat);
result = myDateFormat.format(test);
//System.out.println(" reslut date is "+result);
} catch (Exception e) {
System.out.println(" Exception is "+e);
return result;
public static Date stringToDate(String strDate,String dateFormat1){
Date result1=null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat1);
result1=myDateFormat.parse(strDate);
catch(Exception e){
System.out.println(" exception is "+e);
return result1;
}I am facing problem in getting the actual date. Please suggest the solution. -
Conversion of a data object of type "C" to type "l" is not supported
Experts:
i have below code in my FM; defined as remote-enabled module.
when i execute i get the error analysis as:
You attempted to move one data object to another.
This is not possible here because the conversion of a data object
of type "C" to type "l" is not supported.
This at the line move <FS2> TO <wwa_mdm_name_value_pair>-VALUE .
what are the steps to debug this? Thanks!
DATA: tt_mdm_name_value_pair_table TYPE mdm_name_value_pair_table.
FIELD-SYMBOLS : <wwa_mdm_name_value_pair> LIKE LINE OF tt_mdm_name_value_pair_table.
FIELD-SYMBOLS <FS1> TYPE ANY.
FIELD-SYMBOLS <FS2> TYPE any.
data:st_mdm_name_value_pair type mdm_name_value_pair.
assign st_mdm_name_value_pair to <wwa_mdm_name_value_pair>.
assign st_mdm_name_value_pair-code to <FS1>.
assign st_mdm_name_value_pair-value to <FS2>.
clear wa_ZSTRESULT.
loop at T_UPDATE into wa_ZSTRESULT.
assign wa_ZSTRESULT-field to <FS1>.
<wwa_mdm_name_value_pair>-CODE = <FS1>.
assign wa_ZSTRESULT-VALUE to <FS2>.
move <FS2> TO <wwa_mdm_name_value_pair>-VALUE .
append <wwa_mdm_name_value_pair> to tt_mdm_name_value_pair_table.
endloop.resolved using GET REFERENCE.. code looks as below: Thanks!
DATA: tt_mdm_name_value_pair_table TYPE mdm_name_value_pair_table.
FIELD-SYMBOLS : <wwa_mdm_name_value_pair> TYPE LINE OF mdm_name_value_pair_table.
FIELD-SYMBOLS <FS1> TYPE ANY.
FIELD-SYMBOLS <FS2> TYPE DATA.
TYPES t_dref TYPE REF TO DATA.
DATA dref TYPE REF TO DATA.
DATA: TT_UPDATE TYPE ZTYRESULT.
FIELD-SYMBOLS : <WA_UPDATE> LIKE LINE OF TT_UPDATE.
data: st_mdm_name_value_pair type mdm_name_value_pair.
assign st_mdm_name_value_pair to <wwa_mdm_name_value_pair>.
assign st_mdm_name_value_pair-code to <FS1>.
assign st_mdm_name_value_pair-value to <FS2>.
clear wa_ZSTRESULT.
TT_UPDATE = T_UPDATE.
loop at TT_UPDATE assigning <WA_UPDATE>.
assign <WA_UPDATE>-FIELD to <FS1>.
<wwa_mdm_name_value_pair>-CODE = <FS1>.
assign <WA_UPDATE>-VALUE to <FS2>.
GET REFERENCE OF <WA_UPDATE>-VALUE INTO dref.
* MOVE dref TO <wwa_mdm_name_value_pair>-VALUE.
<wwa_mdm_name_value_pair>-VALUE = dref.
append <wwa_mdm_name_value_pair> to tt_mdm_name_value_pair_table.
endloop. -
Remove text to the left of a string or data field
Post Author: masto123
CA Forum: General
Hi there,
i'm pretty new so I am not that clear with the syntax.
I have a field called part id which displays records of the following;
HSV-123456
HSV-1234567
HSV-123456789
I wish to remove the HSV- at the start of the part id. I have used the right function however because some of the parts are longer than others I couldn't do it this way. Is there syntax which removes the first 4 characters of a string or data field?
pls help.
cheersPost Author: masto123
CA Forum: General
pls disregard request, I found the function Mid -
Formatting incoming string with date/time classes?
Hello,
In the software I am writing currently I am @ a certain point talking to an external device. sending requests, receiving responses.
One of the things I find in the response is "20090429094222", as a string.
I cannot change anything to that, thats the way I get it from the device, so thats where I'll have to start with.
As you could probably guess this is a date and a time. Now my question. Is there a good way to format this from 20090429094222
to
2009-04-29 09:42:22
using date and or time classes, not using String operations?
Thanks in advance.I found a class containing 2 functions who do exactly what I need, for those intrested:
public static Date convertStringToDate(String txtFormat, String txtDate) {
DateFormat dateFormat = new SimpleDateFormat(txtFormat);
Date date = dateFormat.parse(txtDate);
return date;
public static String formatDate(Date date, String txtFormat) {
DateFormat dateFormat = new SimpleDateFormat(txtFormat);
String txtDate = dateFormat.format(date);
return txtDate;
}Using them this way gives me exactly what I want:
Date dt = DateUtil.convertStringToDate("yyyyMMddHHmmss", incomingDateSTring);
String newDateString = DateUtil.formatDate(dt, "yyyy-MM-dd HH:mm:ss");Problem solved, thanks alot to those who gave me some explanation on the problem. -
How to read a data file combining strings and data
Hello,
I'm having a data file combining strings and datas to read. I'm trying to read the filename, time, constants and comments into four seperate string indicators (the lines for the comments varies for different files). And read the data into a 2-D numeric array. How can I do this? Is there any function that can serch special characters in the spreadsheet file so I can exactly locate where I should start reading the specific data. The following is how the data file appears. Thank you very much.
Best,
Richard
filename.dat
14:59:00 12/31/2009
Sample = 2451
Frequency = 300, Wait time = 2500
Temperature = 20
some comments
some comments
some comments
some comments
some comments
7.0000E+2 1.5810E-5
7.0050E+2 1.5400E-5
7.0100E+2 1.5500E-5
7.0150E+2 1.5180E-5
Message Edited by Richard1017 on 10-02-2009 03:10 PM
Solved!
Go to Solution.Hi,
I'm fairly new to the NI forums too and I think you just have to wait longer. Your post was done right. I do a similiar function as to what you are talking about except I read in numbers from a file. I create an ini file (just a notepad file of type *.ini) that is is set up with sections inside brackets [] and keys with whatever name followed by an = sign. You may be able to use a *.dat file too, I just haven't. Then the vi attached goes to that file and reads the keys from those sections. You just repeat for the different sections and keys you want to read. You can use similar provide VI's to write to that same file or create it. Let me know how that works.
Attachments:
Help1.ini 1 KB
Help1.vi 10 KB -
Conversion of user date to system format
i have a problem in conversion of user date.
i use a function module in which the user have to give the date as input. he can give the date in any format like MM/DD/YYYY or DD.MM.YYYY etc . how to convert the given date into the system date.hi,
use FM CONVERT_DATE_TO_INTERNAL
cheers,
sasi
Maybe you are looking for
-
Dear Sir, We need to dvelop a Report which can give information related to Material Purchases with following information like : Material Code , GR Number , Material Qty , Basic Value , Excise Duty (Basic) , CST , VAT etc . The above mentioned amount
-
Problem in multi master replication creation using DBA Studio -- replication
Hi, I am trying to create multi master replication using DBA studio but facing following problem at the time of master group creation. ORA-04052 error occured when looking up remote object SYS.SYS@CBOLDATA ORA-00604 error occured at recursive SQL lev
-
Mac Pro with Lion 10.3 'forgets' its optical drives
I've got a really weird problem here, and I think that I can discount a hardware fault since this problem manifests on two Mac Pros (a 2009 Octo-core and a 2009 Quad-core). When I start either of these machines up with Snow Leopard, theres no proble
-
Yosemite: Turning off Macbook Pro screen (lid open) with external monitor connected
Here we go again, this worked pre-Yosemite. Now it seems this trick no longer works. After following these steps again the screen on my Macbook Pro now turns on after logging in and opening the clam shell. Anyone figure out/know a way to turn off the
-
How to resize series of subtitles created by text generator??
Hi, My client wants to change a series of subtitles that is created by a smaller font size. I've looked into the FCP menu and can't find a shortcut that can easily change the font size of a series of subtitles. Instead of clicking it one by one, if t