+ Reply to Thread
Results 1 to 4 of 4

Extract date from SQL timestamp format

  1. #1
    Registered User
    Join Date
    09-14-2014
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    9

    Extract date from SQL timestamp format

    Hello,

    I have extracted data from SQL DB where one of the columns contains the timestamp of entry in the following format:
    08/06/2015 08:10:22 AM

    Now I wish to view entries falling on a specific month, i.e. only entries in May for example. However, I can't do this unless I change the format of the date to be DATE rather than timestamp text. How can I do this?

    I tried changing the format using custom but nothing would change. Also using text function didn't help.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Extract date from SQL timestamp format

    I tried changing the format using custom but nothing would change. Also using text function didn't help.
    Thats probably because they are already text

    without seeing a sample of what you have, 2 options come to mind...
    1. use a helper column with this formula, copied down...
    =DATEVALUE(A1)

    2. Use Text2Columns...
    highlight the data
    Data tab/Data Tools/Text2Columns
    select Delimited
    next/next/ckeck date and select a format/Finished
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    09-14-2014
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    9

    Re: Extract date from SQL timestamp format

    Let me show you an example of the data that I have

    A B C
    1 Serial Name Date
    2 ID1 John 08/06/2015 09:50:05 AM
    3 ID2 Mary 25/05/2015 07:26:32 AM
    4 ID3 Michael 16/04/2015 12:38:06 PM

    Date column is already in Date format (right-click, format, date...etc) but it is not being treated as date (doing month(C2) returns #VALUE! for example, rather than June).

    Doing datevalue also returns #VALUE! error, so I'm not sure what I'm missing here.

    However, using text2column I was able to separate the cell contents and work from there.


    Thanks a lot!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Extract date from SQL timestamp format

    Hi,

    As Ford has said it's likely that column C values are strings of text rather than date/time values. Don't confuse how a cell is formatted with what it actually contains. You can easily check whether a cell contains a number or text with one of the =ISNUMBER(A1) or =ISTEXT(A1) formulae. The fact that you were able to use Text to columns rather proves this.

    The moral is when you extract data from other systems try to ensure that they contain date/time numbers that Excel can use. A lot of systems will produce numbers rather than text, and without nimber values you can't perform date/time arithmetic.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA - Convert Date/Timestamp into American Date and Military Timestamp
    By ryanmorris in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-01-2015, 03:43 PM
  2. [SOLVED] Need Formula to Change Date Format without changing the timestamp
    By siobeh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-13-2014, 04:41 PM
  3. [SOLVED] Extract date format
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2014, 04:59 AM
  4. [SOLVED] Extract numbers from date to number format
    By Jonathan9 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-21-2013, 09:33 AM
  5. Replies: 2
    Last Post: 01-17-2010, 10:39 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1