Datetime converter

Hi i have a datetime converter to a users local datetime, but
i am getting this error
"{ts '2007-10-07 04:20:21'}" is an invalid date or time
string.
i am not sure why this is?
<cfset startday = #NOW()#>
<cfscript>
tz=createObject("component","timeZone");
setLocale("English (Australian)");
smsDate=lsParseDateTime(startday);
hours=listFirst(SMS_Time,":")+listGetAt(SMS_Time,2,":")/60+listLast(SMS_Time,":")/360;
smsDate=dateAdd("h",hours,smsDate);
serverDate=tz.castToServer(smsDate,Australia/Sydney);
</cfscript>

KeithLaw999 wrote:
> so if i change the datetime format will this code
actually change the forms
> date and time to the eqivilent sever datetime
if you need to handle different locales' date formats to
build selects,
something like this will help:
<cffunction access="private" name="buildLocale"
output="false" hint="creates
valid core java locale from java style locale ID">
<cfargument name="thisLocale" required="yes"
type="string">
<cfscript>
var locale=createObject("java","java.util.Locale");
var tLocale=locale.getDefault(); // if we fail fallback on
server default
var l=listFirst(arguments.thisLocale,"_");
var c="";
var v="";
switch (listLen(arguments.thisLocale,"_")) {
case 1:
tLocale=locale.init(l);
break;
case 2:
c=listLast(arguments.thisLocale,"_");
tLocale=locale.init(l,c);
break;
case 3:
c=listGetAt(arguments.thisLocale,2,"_");
v=listLast(arguments.thisLocale,"_");
tLocale=locale.init(l,c,v);
break;
return tLocale;
</cfscript>
</cffunction>
<cffunction access="private" name="getDateTimePattern"
output="No"
returntype="string" hint="returns locale date/time
pattern">
<cfargument name="thisLocale" required="yes"
type="string">
<cfargument name="thisDateFormat" required="no"
type="numeric" default="1">
<cfargument name="thisTimeFormat" required="no"
type="numeric" default="3">
<cfscript>
var locale=buildLocale(arguments.thisLocale);
var tDateFormat=javacast("int",arguments.thisDateFormat);
var tTimeFormat=javacast("int",arguments.thisTimeFormat);
var
tDateFormatter=createObject("java","java.text.DateFormat").getDateTimeInstance(tDateForma t,tTimeFormat,locale);
return tDateFormatter.toPattern();
</cfscript>
</cffunction>
<cffunction access="public" name="getDatePartOrder"
output="No"
returntype="string" hint="returns date part order
(day-month-year,
month-day-year, etc.) for this calendar/locale">
<cfargument name="thisLocale" required="yes"
type="string">
<cfset var datePartOrder="">
<!--- another special case, hong kong mixes chinese chars
--->
<cfif arguments.thisLocale EQ "zh_HK">
<cfset datePartOrder="year month day ampm time">
<cfreturn datePartOrder>
</cfif>
<!--- every place else --->
<cfset
datePartOrder=getDateTimePattern(arguments.thisLocale,3,3)>
<!--- short
date/time formats --->
<cfset datePartOrder=rereplace(datePartOrder,"a","ampm
","All")> <!--- change
ampm --->
<cfset
datePartOrder=rereplace(datePartOrder,"HH:mm|H:mm|HH.mm|hh:mm|h:mm|h.m.","time","All")>
<!--- change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"yyyy|yy","year","All")>
<!---
change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"MM|M","month","All")>
<!---
change date bits --->
<cfset
datePartOrder=rereplace(datePartOrder,"dd|d","day","All")>
<!--- change
date bits --->
<cfset datePartOrder=rereplace(datePartOrder,"/|-|\.|,","
","All")> <!---
change delimiters --->
<cfset datePartOrder=rereplace(datePartOrder," ","
","All")> <!--- clean up --->
<cfreturn datePartOrder>
</cffunction>
<cfscript>
locales=listToArray("en_US,en_GB,fr_FR,fr_CA,en_CA,th_TH,ar_YE");
for (i=1; i LTE arrayLen(locales);i=i+1) {
writeoutput("#locales
#: #getDatePartOrder(locales)#<br>");
</cfscript>
this mess (actually part of a larger CFC that handles i18n
stuff) will return a
date part order for whatever locales you feed it (has to be
java style locale
IDs, if you're on cf7 or later you can use those in place of
the old,
long-winded cf style locales). from that you can arrange your
selects in the
correct order for your users & correctly lsParseDateTime
what they pick into a
valid cf datetime.

Similar Messages

  • Javascript - custom datetime converter problem

    Hi all,
    JDev version 11.1.2.4
    After migration from JDev 11.1.2.1 to new JDev 11.1.2.4 my custom datetime converter stop working.
    After debuging I found out that client javascript converter is problem.
    Here is javascript code:
    function DateToCalendarConverter(pattern, locale, exampleString, type) {
      this._class = "rmypackage.view.convert.DateToCalendarConverter";
      this._separator = '';
      this._pattern = pattern;
      this._locale = locale;
      this._exampleString = exampleString;
      this._type = type;
      this.old_getAsObject = TrDateTimeConverter.prototype.getAsObject;// TrDateTimeConverter is not defined
    DateToCalendarConverter.prototype = new TrDateTimeConverter();
    DateToCalendarConverter.prototype.getAsObject = function (stringValue, label) {
      //some transformation
      return this.old_getAsObject(stringValue, label);
    Line that breaks javascript is " this.old_getAsObject = TrDateTimeConverter.prototype.getAsObject; " and message is TrDateTimeConverter is not defined.
    This works fine in JDev 11.1.2.1.
    Does anyone know what is the problem and is there any workaround?
    Thanks in advance

    Frank, this is not trinidad issue. Which JavaScript libraries ADF loads is definitely changed.
    In JDev version 11.1.2.1 there was Common2_0_0_beta_2.js file, and in JDev version 11.1.2.4 it doesn't exist.
    Unfortunately that file contained TrDateTimeConverter and that is why it doesnt work.
    So, is there a way I can force adf to load javascript library that contain TrDateTimeConverter?
    Oracle?
    Thanks in advance.

  • Datetime converter problem

    hi all,
    I have a prob with datetime converter
    <h:inputText id="toTime" value="#{shiftMBean.shift.toTime}" styleClass="GeneralTxt" maxlength="15" >
    <f:convertDateTime type="time" pattern="H:mm" timeStyle="short" />
    </h:inputText>
    i m gettin error when i enter time as 1:30 or 21:30 or 01:30 can any one pls help me with this??
    toTime is of type time in database

    Your bean must have a getShift() method that return an object that have a getToTime() method that return a Date object... is your bean right?

  • Datetime Convertion

    hello ....
    I have a Flex application that reads from a WebService ...
    and this is supposed to be the value : 2007-08-15T09:25:5 (or
    that's how ASP.NET puts it)
    but when it's displayed in either datagrid or graph ...
    i got this .. Wed Aug 15 03:25:00 GMT -0600 2007
    any thoughts on converting the date to a local time format
    by the way - i've try passing the datetime in as a string
    (which works , except i can't really sort it correctly)

    i think i found a solution ....
    so i ended up writing/looking up a custom sort function
    (which is not that hard)
    that's the sort function
    private function date_sortCompareFunc(objA:Object,
    objB:Object):int {
    var dateA:Date = new Date(Date.parse(objA.strStartTime));
    var dateB:Date = new Date(Date.parse(objB.strStartTime));
    return ObjectUtil.dateCompare(dateA, dateB);
    which i have to put it in ...
    <mx:DataGridColumn headerText="Start Time"
    dataField="strStartTime" sortCompareFunction="date_sortCompareFunc"
    />
    and that's it ...
    and my datetime has the format of -
    8/15/2007 9:30:55 AM
    the solution is found here :
    http://blog.flexexamples.com/2007/08/12/sorting-date-columns-in-a-datagrid/
    =)
    daniel

  • DateTime converting into hrs

    Hi.
    What is the sytanx used when calculating the avg time taken to resolve a ticket? 
    I have the Arrival Date /Time  and Resolved Date/Time field .  This is how I used but the results seems to incorrect.
    Say if I have  ArrivalTime(7/1/2009   5:25:15PM) and ResolvedTime (7/1/2009   7:19:58PM), the formula that I used is
    (ResolvedTime - ArrivalTime) , but the calculation is wrong.  I am missing something out.
    Your help on this is greatly appreciated.
    Thanks
    Cauvery

    Hi Cauvery,
    if your DateTime diffrence should not exeed 24 hours(I day), you will get result in Time() format itself. with the following solution.
    numbervar tsecs := datediff("s",{StartDateTime},{EndDateTime}); // number of seconds between the dates
    tsecs := remainder(tsecs,86400); // find the left over seconds(86400 is seconds in a day)
    numbervar nhours := truncate(tsecs/3600); // divide by the seconds in an hour
    tsecs := remainder(tsecs,3600); // find the left over seconds
    numbervar nmin := truncate(tsecs/60); // divide by the seconds in a minute
    tsecs := remainder(tsecs,60); // find the left over seconds
    time(nhours,nmin,tsecs); //Clubing # values with Time() function
    If the Date diffrence will exeed 24 hours wee need to calaculate Days also. Like
    numbervar tsecs := datediff("s",{StartDateTime},{EndDateTime}); // number of seconds between the dates
    numbervar ndays := truncate(tsecs/86400); // divide by the seconds in a day
    tsecs := remainder(tsecs,86400); // find the left over seconds(86400 is seconds in a day)
    numbervar nhours := truncate(tsecs/3600); // divide by the seconds in an hour
    tsecs := remainder(tsecs,3600); // find the left over seconds
    numbervar nmin := truncate(tsecs/60); // divide by the seconds in a minute
    tsecs := remainder(tsecs,60); // find the left over seconds
    if ndays > 0 then
    nhours:=nhours+ndays*24;
    totext(nhours,0)+":"+ totext(nmin,0)+":"+totext(tsecs,0) //Making A single String
    Regards,
    Salah.

  • DATETIME CONVERT

    case Types.DATE:
    Date date = rs.getDate(i);
    currentRow.addElement(date);
    break;
    this i snot working for SQL DATETIME format

    What is the error?

  • Convert DocTime to datetime type and format of HH:MM

    Hi Experts!!
    I am setting up an alert that will run every 5 minutes but would like only those docs created in the last 5 to be selected. In order to accomplish this i would like to use the DATEDIFF funtion. But have a problem in that the DocTime is a smallint (why it's not a datetime is beyond me!) How do I convert it to the proper datetime type and format?
    Thx
    Richard

    Hi Richard,
    check with this just change date smallint to datetime
    select
    (select case when len(oi.doctime)=3 then
    convert (datetime,convert(varchar,( convert(varchar,oi.docdate,103) + ' '+ (left(oi.doctime,1)) + ':'+ (right(oi.doctime,2))) ,114),103) else
    convert (datetime,convert(varchar,( convert(varchar,oi.docdate,103) + ' '+ (left(oi.doctime,2)) + ':'+ (right(oi.doctime,2))) ,114),103) end) as PreparationTime
    from oinv oi

  • How to Convert DateTime to Date ?

    This sounds easy, but I'm not progressing as I should.
         element MyDate : Date;
         MyDate = contract.ValidityPeriod.TimePointPeriod.StartTimePoint.DateTime. ;
    The above complains about "Assignment of type DateTime to type Date is not possible".
    I've looked into DateTime functions, but am not getting anywhere.
    Any tips on how to convert a DateTime field to Date field ?

    Afaik, AP.Common.GDT.DateTime does not have a ConvertToGlobalDateTime method, furthermore retrieving the date from the globalDateTime could give you the wrong local date since it does do not consider time zones.
    I would use the similar to the following (no guarantee about correctness):
    import ABSL;
    import AP.Common.GDT;
    var In = contract.ValidityPeriod.TimePointPeriod.StartTimePoint.DateTime;
    // convert To GlobalDateTime
    var timeGlobal = GlobalDateTime.ParseFromString(In.content.ToString()); // not sure whether this is correct -> please verify yourself
    // convert to LOCAL_DateTime using timeZone
    var timeZone = In.timeZoneCode;
    var localDateTime = timeGlobal.ConvertToLocalDateTime(timeZone);
    var localDateTimeStr = localDateTime.ToString();
    // cut off time suffix (starts with "T")
    var localDateStr = localDateTimeStr.Substring(0, localDateTimeStr.Find("T"));
    var date = ABSL:Date.ParseFromString(localDateStr);
    Best regards,
    Ludger

  • Convert sql select statement to oracle

    Hi All,
    Can anyone help me converting this Sql select statement to oracle ....
    -----------------------------------------Query--------------------------------------------------------------
    select emp_master.emp_code ,
    emp_master.dept_cd ,
    attendance_master.daily_attn_code ,
    attendance_master.linked_column ,
    case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))     
    then
    dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
    when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')     
    then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate           
    end ,
    eDocsNetEmployeesLeaveDetails.NoOfDays,          
    case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date     
    then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )     
    else      
    case when location.payroll_status <> 'N'
    then dateadd(mm,1,location.next_pay_date)      
    else location.next_pay_date
    end      
    end as PaymentDate               ,
    isnull(grade_master.leave_type,'C') ,
    eDocsNetEmployeesLeave.StartDate ,          
    eDocsNetEmployeesLeaveDetails.LeaveType
    from eDocsNetEmployeesLeave ,
    eDocsNetEmployeesLeaveDetails ,
    eDocsNetLeaveTypes ,
    emp_master ,
    grade_master ,
    attendance_master ,
    location
    where eDocsNetEmployeesLeaveDetails.RequestID     = eDocsNetEmployeesLeave.RequestID and
    eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
    eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
    eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
    location.loc_cd = emp_master.loc_cd and
    attendance_master.loc_cd = emp_master.loc_cd and
    attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
    grade_master.loc_cd = emp_master.loc_cd and
    grade_master.grade_cd = emp_master.grade_cd and
    eDocsNetEmployeesLeaveDetails.RequestID      = @RequestID
    order by eDocsNetEmployeesLeaveDetails.StartDate
    Thanks in Advance
    Smiley

    Seems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
    Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
    Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
    Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual.

  • Convert varchar(255) to varchar(50)

    I want to transfer data from a staging table to another table. The staging table has columns with datatypes I don't always want, and I'm converting them like so:
    INSERT INTO [dbo].[my_table]
    SELECT CONVERT(datetime,TimeIndex,103),
    CONVERT(decimal(6,3),Network_In,3),
    CONVERT(decimal(6,3),Network_Out,3),
    CONVERT(decimal(6,3),Network_Total,3)
    FROM [dbo].[staging_table]
    How would I convert varchar(255) to varchar(50)?
    Thanks in advance
    Adam

    Using substring is returning the column so thanks but now I can't convert datetime for some reason:
    INSERT INTO [dbo].[mytable]
    SELECT SUBSTRING(ClusterName,1,50) AS 'ClusterName',
    CONVERT(datetime,TimeIndex,103),
    ClusterID,
    CONVERT(decimal(3,2),Memory,3),
    CONVERT(decimal(3,2),CPU,3),
    CONVERT(int,CPUTotal),
    CONVERT(int,MemoryTotal)
    FROM [dbo].[stagingtable]
    GO
    Now I get an error I didn't get before:
    Implicit conversion from data type datetime to decimal is not allowed. Use the CONVERT function to run this query.
    But if I run the datetime convert on it's own as a single column select then it works okay. Any ideas where I've gone wrong there?
    To sum up - the above fails but the below works:
    SELECT CONVERT(datetime,TimeIndex,103) AS 'TimeIndex'
    FROM [dbo].[stagingtable]
    Thanks
    Adam

  • Varchar to datetime conversion out-of-range

    I'm importing data from CSV and I get the following conversion datetime error:
    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
    The statement has been terminated.
    I'm using the following statement to convert the datetime from varchar(100) to datetime:
    CONVERT (datetime,TimeIndex,103)
    The date in the CSV is in the following format:
    2015-01-31 23:58:19
    Any ideas what could be causing this?
    Thanks in advance
    Adam

    This could be because of british/American date formats.
    Try importing the following dates: -
    2015-01-01
    2015-01-02
    2015-01-12
    ... and see if that works, then try importing 2015-01-13 and see if that works
    Please click "Mark As Answer" if my post helped. Tony C.

  • Sort Datetime and Varchar Challenge

    Hi! I want to sort datetime (converted to varchar) and varchar together , here is test data generation sql.
    SELECT CONVERT(VARCHAR(10),GETDATE()-3,111) AS TEST_DATE INTO #TMP_TEST
    INSERT INTO #TMP_TEST SELECT CONVERT(VARCHAR(10),GETDATE()-5,111)
    INSERT INTO #TMP_TEST SELECT CONVERT(VARCHAR(10),GETDATE()-7,111)
    My expected result should be date in descending order and 'Not Specified' on bottom.
    I've tried following sql but 'Not Specified' always on top.
    SELECT * FROM #TMP_TEST
    UNION ALL
    SELECT 'Not Specified'
    ORDER BY TEST_DATE DESC
    A very bad workaround is to add a space in the beginning of 'Not Specified', like this ' Not Specified' and the result works.
    Just want to consult if there is a better way to meet my requirement. 
    BTW, TEST_DATE list would be used in Reporting Service query criteria, let user pick a date to query. 'Not Specified' means query ALL TEST_DATE.
    Thank you in advance.

    Check this conditional order by statement:
    SELECT  CONVERT(VARCHAR(10),GETDATE()-3,111) AS TEST_DATE INTO #TMP_TEST
    INSERT INTO #TMP_TEST SELECT  CONVERT(VARCHAR(10),GETDATE()-5,111)
    INSERT INTO #TMP_TEST SELECT  CONVERT(VARCHAR(10),GETDATE()-7,111)
    INSERT INTO #TMP_TEST SELECT  CONVERT(VARCHAR(10),GETDATE()-6,111)
    INSERT INTO #TMP_TEST SELECT  CONVERT(VARCHAR(10),GETDATE()-1,111)
    INSERT INTO #TMP_TEST SELECT  'Unknown'
    SELECT * FROM #TMP_TEST ORDER BY CASE WHEN ISDATE(TEST_DATE) = 1 THEN TEST_DATE END DESC 

  • Attaching Converter with InputDate programmatically

    I am add controls dynamically at runtime through code. Everything works fine but when i attach a converter with InputDate control, i get just a text field instead of inputDate with following error message on console:
    "<SimpleInputDateRenderer> <_hasPopupChooser> The converter supplied for InputDate with ID: null does not implement the ClientConverter interface: [email protected]be5a6a.
    The input field will not support client conversion or validation, and only the input field will be displayed (no date-picker popup).
    To get client conversion and validation support, implement the org.apache.myfaces.trinidad.convert.ClientConverter interface or obtain the converter using javax.faces.application.Application.createConverter (preferred).
    If you just want to set the converter pattern programmatically, obtain it using createConverter and call setPattern() on it.
    My code is as follows:
    RichInputDate rid = new RichInputDate();
    DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("oracle.adf.rich.DateTime");
    converter.setPattern("MM-DD-yyyyy");
    rid.setConverter(converter);
    binding_pflContents.getChildren().add(rid);
    Kindly help me

    The problem is the converter id (oracle.adf.rich.DateTime) you use to get the converter. This converter need an internal wrapper class (oracle.adfinternal.view.faces.convert.DateTimeConverterWrapper) t owork. The problem is that you should not use this class in your code as it is an internal class.
    Instead you can use the normal "javax.faces.DateTime" converter id
    import javax.faces.convert.DateTimeConverter;
            DateTimeConverter converter =
                (DateTimeConverter) FacesContext.getCurrentInstance().getApplication()
                .createConverter("javax.faces.DateTime");
            converter.setPattern("MM-DD-yyyyy");Timo

  • Convert Month to Range of Dates

    Hi All,
    I need help it writing a T-SQL which converts a single month into the all the dates of that month.
    I tried and tried, and  nothing came to my brain. I need from experts like you.
    Table Data
    P_Status
    Month Daily Prod
    Unit
    Jan-14 1
    4
    Feb-14 3
    6
    The output needs to be like this 
    Month Daily Prod
    Unit
    1/1/2014 1
    4
    1/2/2014 1
    4
    1/31/2014 1
    4
    2/1/2014 3
    6
    2/2/2014 3
    6
    2/28/2014 
    3 6
    Thanks in advance.

    if you can't (or don't want to) create a calendar table (you should, its super helpful) then you could use this function instead:
    create function Dates(@date datetime)
    returns @table table
    now datetime,
    today datetime,
    Month_start datetime,
    Month_end datetime,
    Prev_Month_Start datetime,
    Prev_Month_End datetime,
    Week_Start datetime,
    Week_End datetime,
    Prev_Week_Start datetime,
    Prev_Week_End datetime,
    Quarter_Start datetime,
    Quarter_End datetime,
    Prev_Quarter_Start datetime,
    Prev_Quarter_End datetime,
    Year_Start datetime,
    Year_End datetime,
    Prev_Year_Start datetime,
    Prev_Year_End datetime,
    Month_End_TS datetime,
    Prev_Month_End_TS datetime,
    Week_End_TS datetime,
    Prev_Week_End_TS datetime,
    Quarter_End_TS datetime,
    Prev_Quarter_End_TS datetime,
    Year_End_TS datetime,
    Prev_Year_End_TS datetime,
    Year smallint,
    Month smallint,
    Day smallint,
    Month_Name varchar(15),
    Day_Name varchar(15),
    WD smallint
    as
    begin
    if @date IS NULL set @date = getdate()
    insert into @table
    select
    @date as now,
    convert(datetime,convert(varchar,@date,101)) as today,
    dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
    dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
    dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
    dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
    dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
    dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
    dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
    dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
    convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
    convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
    dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
    dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
    dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
    dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
    dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
    dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
    dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
    dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
    dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
    dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
    Year(@date) as Year,
    Month(@date) as Month,
    Day(@Date) as Day,
    datename(month,@Date) as Month_Name,
    datename(WEEKDAY,@date) as Day_Name,
    datepart(weekday,@date) as WD
    return
    end
    go
    select * from dbo.Dates(getdate())
    go
    drop function dbo.dates

  • Convert this sql server query to Oracle?

    I've some SQL Server queries that I need to make a copy for to run against Oracle databases. (10G), any help would be appreciated.
    SELECT COUNT(*) COUNT, CONVERT(DATETIME, CONVERT(VARCHAR(8), M.START_DATE, 1)) [DATE]
         FROM OPTC.ORD_M_ORDER M
         INNER JOIN OGEN.GEN_M_PATIENT_MAST P ON M.PAT_NUMBER = P.PAT_NUMBER
         INNER JOIN OPTC.ORD_C_ORDER_TYPE C ON C.ORDER_TYPE_KEY = M.ORDER_TYPE_KEY
         WHERE OGEN.DATEONLY(END_DATE)- OGEN.DATEONLY(START_DATE) < '1900/03/01'
         --AND OGEN.DATEONLY(CREATED_ON) = OGEN.DATEONLY(CURRENT_TIMESTAMP)
         AND ORDER_STATUS IN (4,7,8)
         AND M.FACILITY_KEY IN (SELECT VALUE FROM OGEN.COMMA_TO_TABLE(@FACILITYKEY))
         AND [START_DATE] BETWEEN @STARTDATE AND @ENDDATE
         AND CAST(M.ORDER_FLAGS AS BIGINT) & 64 <> 64 AND P.DISCHARGE_DATE IS NULL
         GROUP BY CONVERT(DATETIME, CONVERT(VARCHAR(8), [START_DATE], 1))

    Hi,
    You could use the 'Translation Scratch Editor' in SQL*Developer to translate SQL*Server statements to Oracle.
    SQL*Developer is free and can be downloaded from here -
    http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
    Once installed start it up, then go to 'Tools' - 'Migration' - 'Translation Scratch Editor'
    I did run the statement you have posted here through it but it gave errors so looks like there may be a problem with the syntx in any case.
    Does this query run as it is in SQL*Server ?
    Regards,
    Mike
    Edited by: mkirtley on Jan 5, 2012 12:45 PM

Maybe you are looking for

  • Difference in Stock account , Custom clearing account

    Hi All. I found the amount difference issue when GR document is reversed. The background is as follows. 1. Material is procured from import vendor for which PO order currency is CNY. 2. The conditions maintained in PO are indian standard customes con

  • Prevent the dock to move from one screen to another.

    I have two external monitors connected to my mac and every some time the dock moves to the bottom of screen one (where all my destop icoms are located) to monitor two (no icons). How I can fix this. I want my dock in the same place all the time.

  • Naming a variable from a string

    Hi, I am trying to convert a String into a variable name. for example "namevariable" is converted to the variacle name and then used like below: namevariable = new classname( ); any ideas ? thanks

  • XML Parser for Java version 2.0.2.9

    I can no longer find the XML parser for Java (version 2.0.2.9) for Sun Solaris and Oracle version 8.1.7.3. This would be the file xmlparserv2.jar for parser version 2.0.2.9 This file support the latest Oracle Applications work flow version and so is

  • HT203167 i synced my iPhone 4 onto my iMac and i lost over 90 songs HELP

    i had 138 songs after i synced my phone it left me with 44. and they were my most recent purcheses. now the only thing in iTunes is like 30 sum songs. HOW DO I FIND THE LOST MUSIC???? please this is so important. im a dj i have to have my music