How to convert datetime to datepart

Hi guys,
I have a datetime and I would like to get the datepart from it.
SELECT 
DATEPART(WEEK,FK_DT_MAILING)
  FROM [LNL_**].[***].[VD_***]
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type datetime.
Anyone know how to solve this? :)

Hi all,
None of the above works. It is a datetime2(7) type column.
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
Try
DECLARE @dt datetime2(7)
SELECT @dt = CURRENT_TIMESTAMP
SELECT DATEPART(week,@dt);
DATEPART can be used in the select list, WHERE, HAVING, GROUP BY and ORDER BY clauses. In SQL Server 2008, DATEPART implicitly casts string
literals asdatetime2 type.
This means that DATEPART no longer supports the format YDM when the date is passed as a string. You must explicitly cast the string to adatetime or smalldatetime type
to use the YDM format.
[Source: DATEPART
(Transact-SQL)]
web: www.ronnierahman.com

Similar Messages

  • Proc C - How to convert datetime variable in Proc C into C?

    Hi,
    Does anyone know how to convert a datetime variable in Pro C into C?
    For Example,
    Order_Table with OrderId and OrderDate fields.
    How do I compare the OrderDate with the system datetime in Pro C or C?
    Thank you.

    Maybe this will help:
    http://asktom.oracle.com/~tkyte/Misc/CTime.html

  • 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

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • DateTime is stored as an int. How to convert to datetime format??

    According to the database, StartTime is stored as int: 471895438
    When Viewed in the software it comes out like this: 9/29/2010
    10:05:26 AM
    Any ideas on how to convert this using sql?
    -Tim

    I tried to play with some "reverse engineer" to get the convert value but I dont see the logic. since I dont find a pure date that fit the convert but maybe this will help:
    declare @I INT = 471895438
    declare @DT datetime = '20100929 10:05:26'
    select
    @DT
    ,DATEADD(MS, @I*(-1), @DT)
    ,DATEADD(SECOND, @I*(-1), @DT)
    --,DATEADD(MINUTE, @I*(-1), @DT) -- out of range
    (No column name) (No column name) (No column name)
    2010-09-29 10:05:26.000 2010-09-23 23:00:30.563 1995-10-16 16:01:28.000
    by those result I guess that it is in MINUTE or SECOND
    and according to those result i will need to guess that one of those convert may work for the OP:
    SELECT DATEADD(MILLISECOND, @I, '2010-09-23 23:00:30.563')
    SELECT DATEADD(SECOND, @I, '1995-10-16 16:01:28.000')
    * I tried to use datetime2 as well and check the result for microsecond and nanosecond but the solution was not better and look like 2010-09-29 10:05:25.5281046, 2010-09-29 09:57:34.1045620
    ** This is really strange if someone use a value like 2010-09-23 23:00:30.563 as a base time, and even the base value 1995-10-16 16:01:28.000 then it look strange! but maybe this is the time that the developer born or some other specific time that fits his
    needs :-)
    ** I used my birthday date (but never not a min time), several times in application that I developed as a base time :-)
    [Personal Site] [Blog] [Facebook]

  • 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.
    ¯\_(ツ)_/¯

  • How to convert the date time from MM-DD-YYYThh:mm:ss to YYYY-MM-DDThh:mm:ss format

    Hi All,
    I have a requirement in my project like to convert the date time from one format to another.my situation is like to convert the date time from MM-DD-YYYThh:mm:ss to YYYY-MM-DDThh:mm:ss format. I am using the soa suite 11.1.1.6.
    Can any one suggest me how to convert in the BPEL transformation.
    Thanks,
    Sanju.

    Hi Sanju,
    Store the date to be converted into a variable viz. dateVar. Now, process an expression in assign as: xp20:format-dateTime($dateVar,'[Y0001]-[M01]-[D01] [h]:[m01]:[s01]').
    Regards

  • How to display datetime like below

    How to display datetime like below
    13-oct-2014 10:11:00
    2014-10-13 10:11:00
    (I always must display seconds as 00)
    format is
    dd-mmm-yyyy hh:mm:00
    yyyy-mm-dd hh:mm:00

    if I use 
    SELECT FORMAT(getdate(),'dd-MMM-yyyy hh:mm:00')
    I'm getting the following error
    'FORMAT' is not a recognized built-in function name.
    Thats because your version is below 2012
    then use the other suggestion which is
    SELECT REPLACE(CONVERT(varchar(12),datefield,106),' ','-') + ' ' + CONVERT(varchar(5),datefield,108) + ':00'
    FROM Table
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to convert Date format into day in ssrs reports?

    Hi
    How to convert date format into day?
    10/01/2010 as like Monday like that?

    =weekdayname(datepart("w",Fields!mydate.Value))
    -Vaibhav Chaudhari

  • How to convert from military time (string) to regular time?

    How to convert from military time (string) to regular time?
    First of all I need to let you know I'm very new to Crystal Reports, so I apologize and will need detailed instructions if possible.
    I have created a Crystal Report pulling information from the received time field.  On the report, the time is showing in military time (ex. 16:00:00).
    How can I convert this time to normal time (ex. 4:00:00)
    Since the field is a 'String' field and not a 'Time' field, I do not have the option of changing it under the field properties.
    I hope someone can help with this.
    Thank you in advance.

    As my fields were date only and not datetime, I ended up using the following,
    If IsDate({CallLog.EmailRecdDate}) Then
         CDate({CallLog.EmailRecdDate})
    Else
         CDate(0,0,0)
    You answer lead me in the right direction.
    I'm still having an issue with the 'Else' statment returning 12:00:00 because of the CDate(0,0,0), but I'm not sure what else I can use to return a blank space on the report.  Any ideas?
    Thanks again!

  • How to convert class file

    Hi all, I am new in java card development.
    This is my environment setting:
    @echo off
    set JC_HOME=C:\JavaCard\java_card_kit-2_2
    set JAVA_HOME=C:\j2sdk14103
    set PATH=.;%JC_HOME%\bin;%PATH%
    I have created the Wallet applet according to 'Zhiqun Chen" text book and named it WalletApp.java.
    I have compiled this file to a class file.
    This is where is I saved my file
    C:\JavaCard\java_card_kit-2_2\samples\src\com\sun\javacard\samples\WalletApp\WalletApp.java.
    But I don't really understand how to convert the class file.
    May I know what is this for?
    -out EXP JCA CAP
    -exportpath
    -applet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1:0x1
    com.sun.javacard.samples.HelloWorld.HelloWorld
    com.sun.javacard.samples.HelloWorld
    0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1 1.0
    must save this in what file?
    I tried to type in the command line below (and the result):
    C:\JavaCard\java_card_kit-2_2\samples>converter -config scr\com\sun\javacard\sap
    les\Wallet\Wallet.opt
    error: file scr\com\sun\javacard\saples\Wallet\Wallet.opt could not be found
    Usage: converter <options> package_name package_aid major_version.minor_ver
    sion
    OR
    converter -config <filename>
    use file for all options and parameters to converter
    Where options include:
    -classdir <the root directory of the class hierarchy>
    set the root directory where the Converter
    will look for classes
    -i support the 32-bit integer type
    -exportpath <list of directories>
    list the root directories where the Converter
    will look for export files
    -exportmap use the token mapping from the pre-defined export
    file of the package being converted. The converter
    will look for the export file in the exportpath
    -applet <AID class_name>
    set the applet AID and the class that defines the
    install method for the applet
    -d <the root directory for output>
    -out [CAP] [EXP] [JCA]
    tell the Converter to output the CAP file,
    and/or the JCA file, and/or the export file
    -V, -version print the Converter version string
    -v, -verbose enable verbose output
    -help print out this message
    -nowarn instruct the Converter to not report warning messages
    -mask indicate this package is for mask, so restrictions on
    native methods are relaxed
    -debug enable generation of debugging information
    -nobanner suppress all standard output messages
    -noverify turn off verification. Verification is default
    *********************************************************May I know What is the correct command line to convert the class file and what must I do to before converting the class file?
    I saw some article saying we must use JDK1.3, is it a must?
    Your solution is highly appreciated.
    Thank you!

    Hi Ricardo,
    I saved the file below as WalletApp.opt in the directory of scr\com\sun\javacard\samples\WalletApp
    -out EXP JCA CAP
    -exportpath c:\javacard\java_card_kit-2_2\api_export_files
    -applet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2:0x1 WalletApp.WalletApp
    WalletApp 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2 1.0
    But I still have the problem below:
    C:\JavaCard\java_card_kit-2_2\samples>converter -config scr\com\sun\javacard\sam
    ples\WalletApp\WalletApp.opt
    error: file scr\com\sun\javacard\samples\WalletApp\WalletApp.opt could not be fo
    und
    Usage: converter <options> package_name package_aid major_version.minor_ver
    sion
    OR
    converter -config <filename>
    May I know What's wrong with my command or file?
    Where can I download JDK because what I can find is J2SDK.
    Thank you!

  • How to Convert MM/DD/YYYY to YYYY/MM/DD in SQL Reporting Services

    i am having difficulty of converting a parameter field, called @startdate, on sql reporting services report to YYYY/MM/DD format.  the parameter @Startdate was set to Data/Time.  @Startdate is 6/1/2014 12:00:00 and I want to convert it
    to 2014/06/01.  I want to compare @Startdate with a column in database called Begindate which is in format of YYYY/MM/DD hh:mm:ss.  I tried the followings
    select * from Atable where cast(Atable.Begindate as date) >= cast(@Startdate as date)
    select * from Atable where cast(Atable.Begindate as date >= cast(convert(datetime, @Startdate) as date)
    SQL Reporting Services only gives me Text, Boolean, Date/Time, Integer and Float.
    Regards,

    Hi Elmucho,
    Sorry for the delay. I tested with the sample data you provided, however everything works well in-house. Could you please creste a new report and check the result. Here are the steps I performed:
    1.  Create a table and insert the following data:
    Name (varchar(50))    Begindate (datetime, not null)    
    Lastdate (datetime, not null)
    bob                          
    2008-01-01 08:08:08.000      2010-10-10  
    10:10:10.000
    alice                         
    2010-10-10 10:10:10.00       2011-11-11
      11:11:11.000
    smith                       
    2011-11-11 11:11:11.00       2012-12-12   
    12:12:12.000    
    2. Open SQL Server Data Tools, create the data source and add the dataset with the below query:
    SELECT     Name, Begindate, Lastdate
    FROM         [tablename ]
    WHERE     (CAST(Begindate AS date) >= CAST(@Startdate AS date)) AND (CAST(Lastdate AS date) <= CAST(@Enddate AS date))
    3. Then, click execute button, it prompts for inputting the parameter value.
    @Startdate        
    6/1/2008
    @Enddate          
    5/1/2014
    Enter the date and press OK.
    4. Here is the result in the query designer:
    Insert a table and fields. Save the report and preview:
    Thanks.
    Tracy Cai
    TechNet Community Support

  • How to convert string to 16 characters.

    My external unique id is too long, more then 30 characters.
    How to convert it to 30 characters using sql?

    You should find another extranal system id in order to mantain uniqueness, but you could also use the name field (that supports 50 characters), but it deppends of which entity you are using.
    Which is the entity? and...if the only way to insert data is by web services the you could use more than one field to verify uniqueness since you can query more than one field at the time.
    Hope it helps
    Kim.

  • How to convert Web app into a channel?

    To whom it may concern,
    Does anyone know how to convert a Web app into a channel inside the Portal server 6.0?
    I developed the web app and tried to create a provider and a channel for it, but the Portal server did not recognize the WEB-INF folder and give me errors saying that it couldn't locate the class files.
    I also have a problem with URL inside my jsp page (channel).
    For example, I have two jsp pages:
    /etc/opt/SUNWps/desktop/default/MyCustomProvider/test1.jsp
    /etc/opt/SUNWps/desktop/default/MyCustomProvider/test2.jsp
    and when I try to put a link from test1.jsp to test2.jsp using
    ... and make a channel based on test1.jsp. The channel will display the link as "http://mydomain/portal/test2.jsp" and result in "Error: page not found". I want the link to point to
    /etc/opt/SUNWps/desktop/default/MyCustomProvider/test2.jsp
    To summarize my questions,
    1) Where should the web app be located in the Portal server?
    2) How to make a link inside one jsp page (channel) to point to another page inside the same folder?
    Thank you in advance

    Hello Karthik,
    I just tried to solve my problem with your suggestions, unfortunately, my JSP channel still doesn't work :(
    The portal server keeps reporting "Server Error..." when I tried to add query at the end of the href.
    Do you still have any other suggestions?
    Thank you

  • Video Format Total Solution: How to Convert and Edit Video on Windows/Mac

    More and More video formats are coming out with different video encoders and it makes our spare time more and more colorful. However, it is not to say that there is no problems. Actually, different video formats make it difficult to share video with others, even your own camcorder and iPod. Is there an easy way to convert videos effectively. Yes, there is.
    In this article, I will show you guys how to convert videos on windows and mac.
    Part 1. How to Convert and Edit Videos on Windows
    For Windows users, you need a Video Converter(http://www.aiseesoft.com/total-video-converter.html) to do that for you.
    Here I use Aiseesoft Total Video Converter(http://www.aiseesoft.com/total-video-converter.html)
    Step 1: Download and install Aiseesoft Total Video Converter
    After you download it to your computer, double click it and it is really easy to install.
    You just need to click “next” and it will complete it in seconds. It will automatically run after installation.
    http://www.aiseesoft.com/images/guide/total-video-converter/screen.jpg
    Step 2: Load Video
    Click “Add File” to find the video that you want to convert and click “open”. It will be loaded automatically.
    Step 3: Select the target to decode
    In the “Profile” drop download list you can find your target according the usage of your output video, such as if you want to put the video on your iPod touch, you can select the “iPod” in the first list and “iPod touch 2 MPEG-4 640*480(*.mp4)” in the second list.
    Step 4: Set Advanced Parameters
    After you select the right output profile, you can click “setting” button to set your advanced parameters. You can adjust video and audio settings separately. In video section, you can change “video encoder”, “resolution”, “frame rate”, “video bitrate”In audio section, you can change “audio encoder”, “sample rate”, “channel”, “audio bitrate”If you want to save this profile and settings and use it next time you can click “save as” button to give a name to it. And the next time you want to use it you can find it in the profile list named “user defined”.
    Step 5: Choose a Destination
    To browse and find a output folder for your output files or just the default one.
    Finally, Click “Convert” button to begin your conversion, here in the converting
    interface you can choose “shut down the computer when conversion complete” or “open output folder when conversion complete” or you just do not choose neither one.
    Tips: How to Edit the Output Video
    This video converter is also a video editor, you can use it to edit your output video as follows:
    http://www.aiseesoft.com/images/guide/total-video-converter/effect.jpg
    1. Effect:
    You are allowed to adjust the “Brightness”, “Contrast”, “Saturation” and you can choose the “deinterlacing” to make the video more enjoyable.
    2. Trim:
    In “Trim” section you can pick up any part of the video to convert.
    There are two ways to select the part of the video you want. One is set the start and end time in the box. The other one is to drag the start and end button in the processing bar.
    3. Crop:
    This function allows you to choose a certain play area to convert. That means you can choose a part of the screen you like to convert. For example, you just like the tv in the middle of the screen, then you can drag the frame around the preview window to select the tv and the output preview will show you the output video.In this section you can also choose the “zoom mode”, such as “keep original”, “full screen”, “16:9”, “4:3”.
    4. Watermark
    In the section, you can add a watermark on the output video to show people something, such as your name, website, studio name or other things. The watermark could be words and picture. You can adjust the transparent of the watermark easily to make it more beautiful.
    Part 2. How to Convert Video on Mac
    This time you need a Video Converter for Mac(http://www.aiseesoft.com/video-converter-for-mac.html)
    Step 1: Add File
    Click “Add File” button to load the video you want to converter
    http://www.aiseesoft.com/images/guide/mac-video-converter/steps.jpg
    Step 2: Choose profile and adjust settings
    You can find your output video format from a drop-list called “Profile”You can also adjust the specific settings of the output video, such as “Resolution”, “Bitrate”, “Encoder” and so on.

    @ Tamwini
    Your only goal is to sell software.
    ‡Thank you for hitting the Blue/Green Star button‡
    N8-00 RM 596 V:111.030.0609; E71-1(05) RM 346 V: 500.21.009

Maybe you are looking for

  • Start up problems help!!!

    hey so my ibook g3 was beginning to have problems. many programs such as ichat,safari or adium would shut down and error messages would come up saying it closed ect. so i decide to restart since it usally solves the problem but this time it didnt. so

  • Not able to edit the value options in LKM

    Hi I have recently upgraded to ODI 11g . In that we are not able to edit the value options in LKM. (i.e.. editor window is not appearing, not able to edit the text. Please let me know the solution . Thanks

  • IPod Nano isn't recognized by iTunes/computer

    I've had my iPod Nano for almost six months now, and up until now I haven't had any problems with it. When I connect it to the computer, it charges but it doesn't say "Do not disconnect", it doesn't sync any new songs and on iTunes, there is no "devi

  • Word wrap by delimiter in Report

    Hi, How Can I have word wrap in report based on delimiter in the column value For eg: My column value in country like AU:NZ , US:UK:CA I want the values to wrapped by delimiter ":" , so that ANZ and NZ comes in two line I tried REPLACE(country, ':' ,

  • Difference in timestamp values

    Hi, We have a project for like to like migration for R12 to R16, but ther are differences in the timestamp values calulated between the two enviornments The R12 Production server is 5 hrs head of R16 production server. i have applied the following fo