Formating dates with to_char function
Hi,,
Inside a pl/sql procedure Im formating a date:
v_start_date := 2011-04-01 05:00:00;
v_start_month := to_char(v_start_date,'mm');and I need that v_start_month returns = 04
but returns 4
What could I do to fix it
Many Thanks..
If you define v_start_month as a number then it will strip off the leading 0 when it displays. Define v_start_month as a varchar and it will display the way you want.
SQL> DECLARE
2 v_month VARCHAR2(10);
3 BEGIN
4 v_month := to_char(SYSDATE,'mm');
5 dbms_output.put_line(v_month);
6 END;
7 /
08
Similar Messages
-
Help! using FM for formating date with to_char()
Hi,
Basically my requirement is to format the date in specific format (i.e. DD MM YYYY HH24:MM) and it should avoid the padding zeros.
Ex: 03-Jun-2009 10:01 should be displayed as 3 Jun 2009 10:01.
I was using the below query
to_char(sr.recievedat, 'FMDD Mon yyyy HH24:MI')...
But the thing is it removing the padding zeros from minuites aswell, which i dont require.
For example,
Ex1: 03-Dec-2009 18:10 3 Dec 2009 18:10
*04-Dec-2009 19:01 4 Dec 2009 19:1.. It should be 4 Dec 2009 19:01*
Can some body help me how to control the FM to restrict the padding to some places
Thanks
PhaniHi try this
sql> select to_char(sr.recievedat, 'FMDD Mon yyyy fmHH24:MI') from dual;example
SQL> select to_char(to_date('01-jan-2009 7:01:06','dd-mon-rrrr HH:MI:SS'), 'FMDD Mon yyyy fmHH24:MI'
) from dual;
TO_CHAR(TO_DATE('01-JAN
1 Jan 2009 07:01 -
Trouble getting a timestamp formatted by a 'to_char' function
We have trouble getting a timestamp formatted by a 'to_char' function and a 'group by'
for a count. By assigning the result of the to_char function to an attribute and
grouping on that attribute, we try to get the frequency of an event.
What happens is a non predictable 'IllegalArgumentException' on
'Timestamp.class' while getting the timestampvalue.
We make use of a scrollablecursor as you can see in the stacktrace.
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
at java.sql.Timestamp.valueOf(Timestamp.java:160)
at oracle.sql.CHAR.timestampValue(CHAR.java:567)
at oracle.jdbc.driver.ScrollableResultSet.getTimestamp(ScrollableResultSet.java:658)
at oracle.toplink.oraclespecific.Oracle9Platform.getObjectFromResultSet(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.getObject(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.fetchRow(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.cursorRetrieveNextRow(Unknown Source)
at oracle.toplink.queryframework.ScrollableCursor.retrieveNextObject(ScrollableCursor.java:512)
at oracle.toplink.queryframework.ScrollableCursor.loadNext(ScrollableCursor.java:357)
at oracle.toplink.queryframework.ScrollableCursor.hasNext(ScrollableCursor.java:233)
After restarting the application server there is a chance that the query returns
with the expected results. But most of the times it just returns the above
mentioned exception.
I don't see the logic in the apparently random parsing of the value.
The column in the database is a timestamp, but that the reason why i'm using the
to_char method.This is a bug in TopLink with ReportQuery. Please report this is Oracle technical support. Basically TopLink is converting to the attribute type, but should not be if a function was applied to the expression.
To workaround the issue you can use getField(/) in the expression instead of get(/) (using the database field name instead of the class attribute name). -
Unusual result with TO_CHAR function on a date
Can anybody explain to me why I see two different results if I use the following SQL in PL/SQL Developer (Oracle Database 10g Enterprise Edition Release 10.2.0.1.0)? I'm not sure if I have a wrong setting in Oracle or PL/SQL Developer, or if I'm just misunderstanding how the TO_CHAR function works. Many thanks.
select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
Results:
SYSDATE
10/02/2009 16:52:32
FORMATTED_DATE
10/02/2009 04:02:32select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
Results:
SYSDATE
10/02/2009 16:52:32
FORMATTED_DATE
10/02/2009 04:02:32It should not be -> mm it should be mi .
Got me?
Regards.
Satyaki De. -
How to use format-date with the report parameter
Hi all,
How to use the format-date function with this tag,
<?param@begin:P_FROM_DATE?><?$P_FROM_DATE?>
this form date is coming from report parameter and is coming like this 2012/11/01 00:00:00.
So now i need this in DD-MON-YYYY fromat.I tried like this <?param@begin:P_FROM_DATE?><?$format-date:P_FROM_DATE;'DD-MON-YYYY'?>
but its giving error. Can any one pls tell how to convert it to customized date format.
thanks & Regards
Srikkanth.MIssue solved.
Ref this link
XML date Format -
Formatting Dates with Javascript
Hi all. I'm tryign to find the solution on the web, but have
not had much
success yet.
I"m working on a customized button my my HTMLArea script that
puts a WYSIWYG
component on my form fields to insert the date.
My code is here:
editor.insertHTML((new Date()).toString());
Which outputs this:
Fri Nov 17 2006 10:08:35 GMT-0600 (Central Standard Time)
What I'm wanting to do is to output
Friday, November 17, 2006 with no timestamp, and no reports
of GMT/CST.
Any suggestions on where I can go to look? I've been at the
W3C, but I did
not see any way to format my string.
I've tried a lot of variations in trying to format the date
witha string,
but have not had any success.
This was my last script, which erred:
var d = new Date();
d.formatDate("D, M j");
d.toString();
editor.insertHTML(d);
TIA,
Jon Parkhurst
PriivaWeb
http://priiva.net.Thanks Mick, Reviewing now.
"Mick White" <[email protected]> wrote in
message
news:ejl3t8$sho$[email protected]..
> crash wrote:
>> Hi all. I'm tryign to find the solution on the web,
but have not had
>> much success yet.
>>
>> I"m working on a customized button my my HTMLArea
script that puts a
>> WYSIWYG component on my form fields to insert the
date.
>>
>> My code is here:
>> editor.insertHTML((new Date()).toString());
>>
>> Which outputs this:
>> Fri Nov 17 2006 10:08:35 GMT-0600 (Central Standard
Time)
>>
>> What I'm wanting to do is to output
>> Friday, November 17, 2006 with no timestamp, and no
reports of GMT/CST.
>
>
http://www.mickweb.com/javascript/dates/customDate.html
>
> editor.insertHTML(customDateString());
>
>
http://www.mickweb.com/javascript/dates/date.js
>
> function customDateString() {
> var now = new
Date(),H=now.getHours(),M=now.getMinutes();
> M=M<10?"0"+M:M;
> d =
>
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
> [now.getDay()]+", ";
> d+=
> ["January","February","March","April","May","June",
>
"July","August","September","October","November","December"]
> [now.getMonth()]+" ";
> d+=now.getDate()+" "+now.getFullYear();
> d+=", "+H%12+":"+M+["AM","PM"][Number(H>11)||H==0];
> return d
> }
>
> Mick
>
>>
>> Any suggestions on where I can go to look? I've been
at the W3C, but I
>> did not see any way to format my string.
>> I've tried a lot of variations in trying to format
the date witha
>> string, but have not had any success.
>> This was my last script, which erred:
>>
>> var d = new Date();
>> d.formatDate("D, M j");
>> d.toString();
>>
>> editor.insertHTML(d); -
Play sound in specified duration and desired file when reading data with VISA functions ?
Hi.
I read data with VISA read function and then I use functions like multiple for showing data on Chart. every thing is OK.
now I want play a specified sound (like a 3s song in my desired folder) when signal amplitude cross over from specified value. then after desired time, it will be wait for new cross over from specified value and this procedure repeat again until I stop the program.
Data comes from MCU and it doesn't stop when system play sound and when system play sound, incoming data for this part (play sound) will be ignore them until specified expired.
I use this VI for reading data and mentioned part which is sound part is empty and I don't know what I must done ?
altougth I use another while loop for sound apart because I want save CPU time.
Thanks.
Solved!
Go to Solution.I would recommend making the data type of the notifier a cluster that contains a path and a numeric (double). The path tells the player which file to play. The numeric is the duration.
Now for a slightly complicated, but really neat, way to stop your second loop. Do not use a second notifier. Instead, send the normal notification but use Not A Path for the path in the cluster. Your second loop can do a check for the Not A Path and stop when that is recieved.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Formatting DATEs with FORMAT clause and not with "to_date()" ?
Well I know I could format a DATE inline with the to_date() function.
But is there a way to format it in a separate FORMAT clause similar to
numbers?
If yes how would a format of
dd.mm.yyyy
or
yyyy.mm.dd hh:mm:ss
look like?user559463 wrote:
Ok, again I am searching something like
COLUMN "expiry" FORMAT "YYYY.MM.DD HH:MM:SS"No, it can only be done via TO_CHAR or NLS_DATE_FORMAT. I think you should read SQL*Plus COLUMN command.
SY. -
How to format date with in the file
Hi,
I have the below data in a file,
101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31201207 1140689340000001
622113010547999999999003 000333333334RE 00030137 onee SYSTEM 0140689340000001
62200000 0000999999999001 0000011111CR460 00030135 twoo system 0140689340000002
82000000040015507087000000000000000003571110D18000_1 140689340000001
Can some one tell me how to read the date which is there in line 1 which is starting with indicator 1 at position 24 to 29
in this example it is 120731
which is in YYMMDD format
I want to replace from 70 to 75 with above date + 2 as 120802 in 2nd line which starts with indicator 5
My output should look like below in a file again
101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31120802 1140689340000001
622113010547999999999003 000333333334RE 00030137 onee SYSTEM 0140689340000001
62200000 0000999999999001 0000011111CR460 00030135 twoo system 0140689340000002
82000000040015507087000000000000000003571110D18000_1 140689340000001
Can some one please tell me how to do this?
Appreciate your response.The following will help you to extract the date and perform an arithmetic function on a date:
olddate=$(head -1 myfile | cut -c 24-29)
newdate=$(date -d "20${olddate} + 2 days" "+%y%m%d")You may have to implement some logic if the year is before this century, e.g 1999. For the rest I suggest you look into awk or sed to perform a string replacement based on character position.
Edited by: Dude on Aug 7, 2012 12:57 PM -
Formatting Date with JavaScript
Hello guys,
is there a way to change the date format with JavaScript? I have a library with different fields.
I hope you can help me!
Best regards
MatthiasYes
Check below
http://www.bentedder.com/convert-a-sharepoint-datetime-field-to-a-javascript-date-object/
function convertSPDate(d) {
* A function to convert a standard SharePoint
* date/time field (YYYY-MM-DD HH:MM:SS) to a
* javascript Date() object
* Author: Ben Tedder (www.bentedder.com)
// split apart the date and time
var xDate = d.split(" ")[0];
var xTime = d.split(" ")[1];
// split apart the hour, minute, & second
var xTimeParts = xTime.split(":");
var xHour = xTimeParts[0];
var xMin = xTimeParts[1];
var xSec = xTimeParts[2];
// split apart the year, month, & day
var xDateParts = xDate.split("-");
var xYear = xDateParts[0];
var xMonth = xDateParts[1];
var xDay = xDateParts[2];
var dDate = new Date(xYear, xMonth, xDay, xHour, xMin, xSec);
return dDate;
// create a couple of variables
var startTime;
var convertedStartTime;
// a standard SPServices call
$().SPServices({
operation: "GetListItems",
webURL: myListURL,
async:false,
listName: myListName,
CAMLRowLimit: 1,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function(i){
// set the value of startTime to standard SP date/time field
startTime = $(this).attr("ows_startTime");
// set the convertedStartTime to a true javascript date
convertedStartTime = convertSPDate(startTime);
http://spservices.codeplex.com/wikipage?title=$%28%29.SPServices.SPConvertDateToISO
http://stackoverflow.com/questions/14283106/beginner-javascript-date-conversion-from-string-to-utc-date-js-into-sharepoint
http://stackoverflow.com/questions/14742625/how-to-convert-utc-date-by-javascript -
Errros in formatting dates with milliseconds
I am writing a routine to convert a String to a Date.
I have created the following mask: "yyyy-MM-dd HH:mm:ss.SSSSS"
I pass this to SimpleDateFormat and then parse to return a java.util.Date.
The method works fine when the milliseconds are all zero, ie .00012. however when the milliseconds increase, the resuting time in the date object becomes anywhere from a minute to hours later than it should be.
For instance, "2006-09-28 10:23:16.214500" becomes
Thu Sep 28 10:26:50 EDT 2006 when the resulting date object is displayed.
Is this a bug with java 1.5?OK thanks, so how would I convert the date string
provided, keeping the millisecond presision? What is
that number if not 21% of a second?Let's say you can get the fractional part (0.214500) into a double variable called fractionalSeconds. You do that part.
int milliseconds = (int) (fractionalSeconds * 1000); // or you might want to round this off - you figure that out
Now you have the number of milliseconds int the above variable. Format your timestamp using the original time string (less the fractional part) plus "." plus milliseconds. Then you could use the parser on that.
That said, I bet you could just get the timestamp as a Java date/time directly rather than parsing it as a string, since you mentioned you're getting this from a database query. -
CREATING A LIST PARTITION WITH TO_CHAR FUNCTION
i want to create a list partitions based on months like 1..12 so that data will go to its respective month partition irrespective of Month and year. i don't have a varchar2 field for month only rather i have got the insertion date column. can anybody tell me how can i create a list partitioned table by using the to_char(date_column,'MON') function.
Range partition means every month one new partition if i go for month wise partition. So, thats final right we cannot use any function to create any list partitions??
-
Change formatting dates with GREP
I am laying out a book with thusands of dates all formatted e.g 02-03-1913. I want to hange these to (eg) 2nd March 1913. I expected it to be a lengthy, staged, operation. But I cannot get GREP to recognise specific numbers (e.g. 02) If worked through logically I did think I could do it in stages. Can anyone help?
Hi,
Using Multi-Find/Change, 12 regex, 1 set. So, 1 click and done!
1/ Search: (0?)(\d+)-01-(\d{4})
Replace by: $2~Sjanuary~S$3
2/ Search: (0?)(\d+)-02-(\d{4})
Replace by: $2~Sfebruary~S$3
12/ Search: (0?)(\d+)-12-(\d{4})
Replace by: $2~Sdecember~S$3 -
Problem with formatting date with JSTL ans swedish locale
Hi,
I have a strange problem with JSTL fmt:formatDate -tag and swedish locale.
-------------------------- Extract from the JSP ------------------------------
<jsp:useBean id="date" class="java.util.Date" />
<fmt:formatDate value="${date}" pattern="dd.MM.yyyy HH:mm" />
With en_US and fi_FI locales date is printed just the way I want: 29.04.2005 13:28 but in se_SE locale it is printed: Fri Apr 29 13:30:09 EEST 2005
Has anyone had this problem before?
Thanks in advance!Hi
Try using "sv_SE" locale. -
Format date with "yyww" doesn't work
Format a date to the format "yyww" doesn't work correctly for the first week of some years. It seams to be weeks that start in December that doesn't work.
DateFormat df = new SimpleDateFormat("yyww", Locale.FRANCE);
String in = "0801";
// Gives: Mon Dec 31 00:00:00 CET 2007
Date d = (Date) df.parseObject(in);
System.out.println(d);
// !? Gives: 0701
String out = df.format(d);
System.out.println(out);Any help appreciated!You're right. ISO 8601 Whichever year contains Thursday determines which year the week belongs to.
The U.S. locale plays by different rules though. At least according to GergorianCalendar, if even one day falls in the new year, it is week 01. This little program displays this:
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import java.text.MessageFormat;
import javax.swing.JOptionPane;
public class CalendarTest {
public static void main(String args[]) throws UnsupportedEncodingException {
try {
if (args.length != 0) {
doYear(new Integer(args[0]).intValue());
return;
} catch (NumberFormatException nfe) {
doYear(2005);
doYear(1998);
doYear(1993);
* Method main
* @param args
public static void doYear(int year) throws UnsupportedEncodingException {
System.out.println();
System.out.println(year);
GregorianCalendar a = new GregorianCalendar(TimeZone.getTimeZone("GMT-8"), Locale.US);
GregorianCalendar b = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"), Locale.GERMANY);
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, Calendar.JANUARY);
a.set(Calendar.DAY_OF_MONTH, 1);
b.set(Calendar.YEAR, year);
b.set(Calendar.MONTH, Calendar.JANUARY);
b.set(Calendar.DAY_OF_MONTH, 1);
while (a.get(Calendar.DAY_OF_WEEK) != a.getFirstDayOfWeek()) {
a.add(Calendar.DAY_OF_MONTH, -1);
while (b.get(Calendar.DAY_OF_WEEK) != b.getFirstDayOfWeek()) {
b.add(Calendar.DAY_OF_MONTH, -1);
do {
System.out.println("US: " + a.getTime() + " " + a.get(Calendar.WEEK_OF_YEAR));
a.add(Calendar.DAY_OF_MONTH, 1);
} while (a.get(Calendar.DAY_OF_MONTH) != 8);
System.out.println();
do {
System.out.println("DE: " + b.getTime() + " " + b.get(Calendar.WEEK_OF_YEAR));
b.add(Calendar.DAY_OF_MONTH, 1);
} while (b.get(Calendar.DAY_OF_MONTH) != 8);
}
Maybe you are looking for
-
Instructions on how to uninstall but no .exe anywhere for windows 8...? Is the link for windows xp-7 actually for 8 as well? or am I not allowed to what my movies that Ive paid apple for?
-
Why won't a pdf convert it's images to a docx file?
I really need to be able to convert images from pdfs into docx files, how can I make this work?
-
Alert notification on Ciscoworks
Alert notification on Campus 3
-
Where I can download the ebook about flex?
I'm new to flex,where I can download the ebook about flex?Thank you.
-
Trouble loading documents into the cloud
I am trying to store word documents in the cloud and I keep getting error messages. Anyone know what is going wrong or what I need to do to be able to store word documents from my mac on the cloud?