Converting UNIX time stamp to local time using T- SQL

Hi All,
I am getting DateTime in UTC time (UTC time (Coordinated Universal Time or Greenwich Mean Time))  using (datediff(ss, '1/1/1970', current_timestamp)) . I want to Convert this in my Local DateTime (CST DateTime). How to achieve this in simple way in T-SQL.
thanks,
Venkat

Imports System.Data.SqlTypes
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Server
Partial Public Class UserDefinedFunctions
    'Microsoft.SqlServer.Server.SqlFunction(IsDeterministic=false)
    <SqlFunction()> _
    Public Shared Function displayLocalTime(dt As SqlDateTime) As SqlDateTime
        If (dt.IsNull) Then
            Return dt
        End If
        Return TimeZone.CurrentTimeZone.ToLocalTime(dt.Value)
    End Function
End Class
Apply it to SQL Server and use in SELECT statement
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • Converting UTC time stamp to local time (CET)

    Is there a smooth way to convert a time stamp from UTC time into the local time (e.g. CET)?
    CONVERT TIME STAMP.... Just converts the timestamp from local time zone to UTC, is there another comand to perform the opposite conversion?
    TIA!
    /Armin

    Hi Armin
    The statement does not only convert from local time zone to UTC you can specifiy any timezone:
    CONVERT TIME STAMP time_stamp TIME ZONE tz
            INTO [DATE dat] [TIME tim]
            [DAYLIGHT SAVING TIME dst].
    The following statement can also be used to convert from date time to timestamp.
    CONVERT DATE dat [TIME tim [DAYLIGHT SAVING TIME dst]]
            INTO TIME STAMP time_stamp TIME ZONE tz.
    Regards
    Faaiez

  • Convert Data time stamp to Local Time

    Hello,
    I want to convert this input to local time EST.
    Input:12/8/2006 10:23:00.000000000 PM -06:00
    o/p: EST.Local Time

    Is the input a string? A timestamp? If so, which flavor of timestamp? Something else?
    Normally, you'd want to use a TIMESTAMP WITH LOCAL TIME ZONE data type for this sort of requirement, since it automatically converts data to the client's time zone. Assuming the input is a string and that the client's time zone is set to EST
      1  select cast(to_timestamp_tz( '12/8/2006 10:23:00.000000000 -06:00',
      2                               'MM/DD/YYYY HH24:MI:SS.FF TZH:TZM' )
      3                AS TIMESTAMP WITH LOCAL TIME ZONE)
      4*   from dual
    SCOTT @ nx102 JCAVE9420> /
    CAST(TO_TIMESTAMP_TZ('12/8/200610:23:00.000000000-06:00','MM/DD/YYYYHH24:MI
    08-DEC-06 11.23.00.000000 AM
    Elapsed: 00:00:00.01
    SCOTT @ nx102 JCAVE9420> Justin

  • Time stamp and local time stamp

    Dear sirs...
    i am a little confused about the time stamp datatype and how to handle it in my applications. i want to display the time for every user in its time zone. so the fields in the database are timestamp with local time zone. is this correct?
    i want it to be such that if one stores the time in USA time , the other can display that same data in UK time.
    best regards

    repost

  • Error when converting time stamp in date time time zone CST  in IC

    Hi Experts,
    We have recently upgraded from CRM 5.0 to CRM 2007. We are using IC WEB Employee interaction center.
    so when agent create service ticket in interaction center and close the ticket on same day we are getting an error saying Error when converting time stamp in date time time zone CST.
    we thought there may be problem while installing SAP CRM by basis team in time zone, but we did not find any problem.
    So please advice how to resolve this issue.
    Regards,
    Teja

    Hi Teja,
    I saw a similar message, and it was resolved by adding a timezone to the user profile defaults tab in SU3. I believe the system has been configured to convert between users' timezone and the system timezone, therefore it needs to know each users' timezone.
    Regards,
    Simon.

  • Convert system time into User local time.

    Hi,
    How to convert System time into User Local time.
    Are there any FMs available.
    Regards,
    Kiran

    hi,
    There is just one simple funda behind the Date and time logic in SAP.
    -> It is absolutely useless to store Date and time directly in DB. Why ?
    Because 00:00 a.m in London could mean 05:30 in India !! So If I (in India) store a Date 1st Feb 2008 , 10:00 a.m .. This time for a person in London could be invalid.. because he is behind your time zone..
    So the solution is to store the date/times in Timestamps format. Taking the above example.. 1st Feb 2008, 10:00 a.m (in India) will be stored as 20080201043000.
    This time if seen in German Time zone will look as : 1st Feb 2008, 05:30 a.m.
    Simple right
    -> In India we store date as DD.MM.YYYY while in other countries they store it as MM.DD.YYYY.
    The separator could be . or - or / .
    The date format is user dependent. I might prefer to store it as DD.MM.YYYY and you might want to store it as MM-DD-YYYY.
    System does not bother what your format is. It always stores in YYYYMMDD (8 Char)
    On screens if you want to display Date then it must always be shown in that users format who is seeing it. How to get this done ?
    DATA : lv_date(10) type c.
    write sy-datum into lv_date.
    So in LV_DATE variable the date will be stores in the users format.
    Simple right
    There are function modules that do the same. But normally we should avoid use of FM to make code simpler, short and easy... no complications at all ..
    You can use system variables sy-datlo (Local Date for Current User) and sy-timlo ( Local Time of Current User ).
    You can also use GET TIME statement.
    reward if useful,
    preet

  • Time difference between local time and server time

    Hi Guys,
    I am currently experiencing a time difference of 40 minutes between the local time and the current server time.
    The local time seems to be 40 minutes slower than my current time.
    Path for Local Time : CMC -> home -> servers -> input.file repository sever -> metrics tab.  (Under the category of Installed on machine peacok, there is a local time.
    Question is how can i sync the local time with my current server time?
    Let me know if more info is required.
    Rgds
    Collin

    Hi Collin,
    Under  CMC >Home >Input FRS , the local time shown is current time of BO Server.
    Since CMC is web-based, any date, time value will be coming from BO Server box.
    u2022     In case your system and BO server is in same time zone  then update the date-time of BO Server
    u2022     In case your system and BO server is in different time zone then check with IT team to figure out the BO Server will be maintained in which time zone.
    u2022     If current requirement is specific to some report then you can add 40 min in all date value in report to get the desired result.
    Thanks,
    Sushil

  • Convert unix time stamp to readable time with daylight saving

    Hello NG,
    I have a table that has a column containing time stamps in the unix time format (seconds since 1970). If I show these times to the user, they should be converted to some readable format. I'm using the following sql code as an example:
    select to_char(
    to_timestamp_tz(
    to_char(
    to_date('01011970','ddmmyyyy') + 1/24/60/60 * 1086508800,
    'YYYY-MM-DD HH24:MI:SS')||' Europe/Warsaw',
    'YYYY-MM-DD HH24:MI:SS TZR'),
    'YYYY-MM-DD HH24:MI:SS TZH:TZM')
    from dual;
    The output I get is the following:
    TO_CHAR(TO_TIMESTAMP_TZ(TO
    2004-06-06 08:00:00 +02:00
    The output is right, but the format I need is the following:
    2004-06-06 10:00:00
    How do I have to alter the statement to get the correct result (add the two hours of the timezone and dst to the time)?
    Any help is appreciated.
    Regards,
    Mario Freimann

    That's the strange thin ... this timezone doesn't exist.
    Running the query I get the error message
    ORA-01882: timezone-region not found
    The results of the statement
    select * from V$TIMEZONE_NAMES;
    for Europe are:
    TZNAME TZABBREV
    Europe/Dublin LMT
    Europe/Dublin DMT
    Europe/Dublin IST
    Europe/Dublin GMT
    Europe/Dublin BST
    Europe/Istanbul LMT
    Europe/Istanbul IMT
    Europe/Istanbul EET
    Europe/Istanbul EEST
    Europe/Istanbul TRST
    Europe/Istanbul TRT
    Europe/Lisbon LMT
    Europe/Lisbon WET
    Europe/Lisbon WEST
    Europe/Lisbon WEMT
    Europe/Lisbon CET
    Europe/Lisbon CEST
    Europe/London LMT
    Europe/London GMT
    Europe/London BST
    Europe/London BDST
    Europe/Moscow LMT
    Europe/Moscow MMT
    Europe/Moscow MST
    Europe/Moscow MDST
    Europe/Moscow S
    Europe/Moscow MSD
    Europe/Moscow MSK
    Europe/Moscow EET
    Europe/Moscow EEST
    Europe/Warsaw LMT
    Europe/Warsaw WMT
    Europe/Warsaw CET
    Europe/Warsaw CEST
    Europe/Warsaw EET
    Possibly something is not right with my installation (Oracle 9.2.0.1.0) ...

  • Appending a creation date/time stamp to a filename using MS Command Language

    I need to access the creation date and time of an existing file and then append that date/time to the filename using MS command language in a .bat file.  The code executes on a Windows server.   I'm looking at different options for doing
    this.  I know it can be done using MS Powershell scripting.  Any other suggestions appreciated.  Thanks

    I tested the answer you supplied here:
    http://social.technet.microsoft.com/Forums/en-US/38873a13-f3f2-40f2-bb96-c1c63722caab/adding-a-datetime-stamp-to-a-file-using-ms-command-language?forum=winserverpowershell
    and it worked.
    Richard Mueller - MVP Directory Services

  • How do you date and time stamp pictures and videos using a EOS Rebel T3?

    I am needing to utilize date and time stamping on videos and photos in my work.  The pictures and videos must display time, a date, and reference number.  I have gone through the cd, owner's manuel and software manuel and I am unclear if I can perform this function. 

    While this is a relatively common feature on point & shoot cameras -- where the photo is thought of as a snapshot to document a memory in a person's life, among DSLR cameras it's not very common (I don't actually know of a DSLR that does this though I don't doubt that it may exist).  DSLR users are usually expecting a higher quality image -- so now the image is thought of more like art and less like a snapshot and the date/time in the corner distracts from the image.  Also they tend to be more advanced users who would be able to modify the image themselves so they have little need for such a feature.
    The camera does record the date & time... but it's in the EXIF data (information recorded into the image file but not displayed).  
    SO... there are programs that will just do this.  You'll need to do a search (I found several but have never tried one so I can't vouch for them).  I think there are Photoshop plug-ins that do this (assuming you have Photoshop). These programs allow you to define the info you want printed (including EXIF data such as date/time) and you get to pick the location, font, size, color, etc. and ultimately the location on the image where you'd like the info displayed.  They then add the info visibly onto the image for you and most support "batch" use (e.g. drop a whole folder of images on it and they'll do them all.)
    Tim Campbell
    5D II, 5D III, 60Da

  • HELP - How to Convert Date in GMT to Local time in Applet

    Hi All
    Is there a way to convert a date from GMT format into a local time say IST in my Java applet, this GMT date is coming from a postgresql database.
    Thanks in advance
    Swaraj

    Try this with your customization:
    java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    java.util.Calendar cal1 = Calendar.getInstance(new SimpleTimeZone((int)(5.5*60*60*1000), "IST"));
    format0.setCalendar(cal0);
    format1.setCalendar(cal1);
    java.util.Date date = format0.parse("2003-01-25 00:15:30");
    java.lang.String formatted = format1.format(date);
    System.out.println(formatted);

  • I am having trouble reading a time stamp on a video using OCR

    I am trying to read a time stamp that is overlaid on a video, using OCR software, but it will not read it correctly I've tried the OCR Preproccessing and Recognition Config VI's and neither have been able to correct to problem I would appreciate some help

    In my experience, it is very important that the contrast not only be
    very good but also that the characters can be easily distinguished
    from the background and that the characters are generally repeatable
    and unique. I've had problems with characters "smearing" into the
    background so that the OCR can't tell where the background ends and
    the character begins.
    Beyond the standard NI OCR stuff, you can use a database to map
    incorrect whole words to correct whole ones in OCR but this only works
    when there is a set of unique words that are significantly different
    from each other. It doesn't work on numbers since any number is
    generally as likely as any other.
    It may be worthwhile to invest in higher quality acquisition equipment
    to improve the image quality. If your video source itself is poor
    quality, then it won't matter though.
    Douglas De Clue
    [email protected]
    nestor wrote in message news:<[email protected]>...
    > Ernest,
    >
    > As "labviewguru" mentioned a screenshot will help a lot to determine
    > if the problem is the image quality. However if you can't post this
    > image then please review the following links I'm attaching here. They
    > talk about OCR and most important, about Filtering, which is mostly
    > used in Vision for image enhancement, noise reduction, sharpen an
    > image, etc. Please review the links mentioned below and apply some
    > filtering techniques to your image. This may help a lot, personally
    > I've used OCR software and I have required in most cases to apply
    > filtering before running the OCR functions.
    >
    >
    > href="http://zone.ni.com/devzone/conceptd.nsf/webmain/E69D110920B99E838625685E0081B881?opendocumen...
    >
    > href="http://zone.ni.com/devzone/devzone.nsf/webcategories/605B55C3100D02188625685E0076C928?opendo...
    >
    > href="http://zone.ni.com/devzone/devzone.nsf/webcategories/E28E087D201C1AD48625685E00824E3C?opendo...
    >
    > Here at the Developer Zone, inside the Development Library you will
    > find in the Vision chapter a lot of information that will be helpful
    > for your development. Please review it. In case you require further
    > assistance you can keep posting questions here at the Discussion Forum
    > or give us a call/email (www.ni.com/ask).
    >
    > Good luck!
    >
    > Nestor Sanchez
    > IMAQ/Motion Support
    > National Instruments

  • Appending and add time stamp at a time........

    Hi all,
    i am working on a scenario...
    it is file based..no mapping and bpm can be used.
    I need to pick up file through xi and append it and put in the target with time stamp to it.
    we can achieve this if mapping or bpm is allowed.....
    But,in file processing we can use only one option at a time.....
    I found a way:
    scenario one: files will be appened and kept in a temparory folder
    using another scenario we will pick up the appeneded file and add time stamp and keep in target structure...
    but i dont think this is advisable...
    please suggest me any other ways to achieve this...(can run operating system command be helpfull??)
    thanks in advance..
    Regards,
    Kiran.

    HI,
    Yes you are right, Appending and adding Time Stamp will not be possible simultaneously.
    Refer - this could help you
    Dynamic Filename with TimeStamp  
    Dynamic Filename with TimeStamp
    /people/william.li/blog/2006/04/18/dynamic-configuration-of-some-communication-channel-parameters-using-message-mapping
    But some how you have to use mapping for it. Then if its allowed to use the mapping then as you have suggested, should have to go for two scenarios. No alternative,
    Probably also you can try with Customized Adapter Module for this.
    Thanks
    swarup

  • Convert Unix timestamp to Readable Date/time

    Hello.
    I'm reading a database with the time field expressed in Unix Time (number of seconds since 1/1/1970 00:00).
    Is there any fast way to convert it to "mm-dd-yyyy hh:mm:ss" ?
    Regards.

    Try something like this:
    DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.LONG);
    String theTime = shortTime.format(new java.util.Date());
    DateFormat shortDate = DateFormat.getDateInstance(DateFormat.MEDIUM);
    String theDate = shortDate.format(new java.util.Date());
    System.out.println("The formatted date is: " + theDate + " and the formatted time is: " + theTime);Check out the static fields in the DateFormat class for the different formatting options.
    Hope that helps!
    - Sheepy

  • Converting unix data to normal date time.

    Post Author: Keshavan
    CA Forum: Formula
    Hi,
    Can anyone help me out on how to convert the unix date time format to normal date time? I should convert this unix data to proper time format also with GMT+5:30 hrs. Please help me to do the same.
    Thanks in advance,
    Keshavan.

    Post Author: V361
    CA Forum: Formula
    Could you provide some samples, I am not sure what a Unix data time looks like.
    Unix date that displays:
    Date you want to display:

Maybe you are looking for

  • Airport Express Audio Via Home Stereo

    Hi, Ive got my Airport Express to play iTunes through my hifi system (after lots of swearing and stuff), but im really disappointed to see it doesnt seem I can play any other audio - for example if im watching tv online etc/any audio not coming for i

  • Firefox crashes when i try to do a search

    Since I upgraded firefox I have been having search problems. If I have the firefox page open and type something in the google search box it takes me to the google search results but when I click on any of them firefox crashes. I get a black screen wh

  • Best way to generate ER diagram

    We have Oracle 11g in our environment. I wanted to know which should be the best way to generate an ER diagram. Below are these steps in SQL developer (version of SQL developer is 3.2.x): a) View → Data Modeler → Browser b) In browser tab, select sho

  • Flickr slideshow alternatives

    Hello again. I need to make a web photo gallery and I recently found out that you can do it though flickr. The problem I'm having is that flickr won't show your pictures unless they're actually photos (no CG images, drawings etc...). The flickr slide

  • TS4124 Who to download all available songs in iTunes Match with one click

    I Purchse iTuens Match. Whow do I download all available songs with only one click. I have more than 4000 songs and I do not want to click and wait for every song.