Remove AM/PM in time and place a leading zero using T-sql

Hi All,
I have a table with time column, lets say my source data looks like this..
Time
8:00AM
10:00AM
1:00PM
12:30PM
9:00AM
My output should look below..basically I need  a t-sql to remove AM /PM and place a leading 0 infront of time if it there is a single digit before colon( : )
Time
08:00
10:00
01:00
12:30
09:00
Create statement:
Create table TimeTest(
ID int null,
Time char(7) null,
Insert Statement:
Insert into Timetest(ID,Time) Values (1,'8:00AM')
Insert into Timetest(ID,Time) Values (2,'10:00AM')
Insert into Timetest(ID,Time) Values (3,'1:00PM')
Insert into Timetest(ID,Time) Values (4,'12:30PM')
Insert into Timetest(ID,Time) Values (5,'9:00AM')
Thanks,
RH
sql

 I guess it depends on what you really want.  If you really truly want the expected results you have listed above, which changes 1pm into 0100, instead of 1300, then you can do this:
SELECT ID
,[Time]
,RIGHT(CAST(CAST(REPLACE(REPLACE(REPLACE([Time], 'AM', ''), 'PM', ''), ':', '') AS int) + 10000 AS varchar(5)), 4) AS [HHMM]
FROM TimeTest
However, if you do want to differentiate between 1:00PM and 1:00AM, making them 1300 and 0100 respectively, then just use the solution from
Jingyang Li

Similar Messages

  • Can I limit the number of appointments made by everyone at a specific time and place?

    I want to limit the number of people who make an appointment at a specific time and place.  Can I do this?

    Which Adobe software are you using?

  • My newer IPhone gets a weaker cell signal at the same time and place as my wife's older one. Help

    My newer IPhone gets a weaker cell phone signal at the same time and place as my wife's older IPhone. Help!

    What is the signal the difference?
    Follow this guide and record the numbers you see...
    http://lifehacker.com/5929546/see-the-actual-signal-strength-on-your-iphone-with -this-quick-tweak
    If the difference is within ~10db there's not much to worry about.
    Now if you see -130 and -80 that is an issue. (talk to your carrier)
    But if you see -60 and -75, both phones are operating normally.
    What are the iPhones in question?
    Are you both on the same network? (what network(s) are you on?)
    What data connection is available on each phone? (3G/4G/LTE)
    Are the iOS and Carrier settings up-to-date?

  • I have a Windows 2003 Server 64-Bit, and when I upgraded to Firefox 4.0.1 now it won't run, it keeps saying to restart to complete the installation, but I've restarted theserver 4 times, and I still can't use it.

    I have a Windows 2003 Server 64-Bit, and when I upgraded to Firefox 4.0.1 now it won't run, it keeps saying to restart the computer to complete the installation, but I've restarted theserver 4 times, and I still can't use it.

    I ended up putting it in DFU mode.  It's kinda hard to tell it was in DFU mode because nothing showed on the screen, it was just black, but the sounds from the computer helped to tell me it was connected.
    Itunes still didn't recognize the device for whatever reason.
    So I used redsn0w.  I don't know if I can say that on these forums, but considering itunes was worthless at this point I am going to give credit where credit is due.
    Now I am giving itunes a second chance to upgrade to 5.1, if it doesn't work, well, back to redsnow and maybe I will even jailbreak it this time rather than just using the fecovery fix found under extras.

  • 2007 iMac freezes up, rainbow wheel appears when this happens. I know the computer is starting to get old but I can't afford a new one at this time and would love to continue using my Mac, but it's frustrating. Would a fresh install or OS upgrade resolve?

    My circa 2007 iMac freezes up, and rainbow wheel appears when this happens. I know the computer is starting to get old but I can't afford a new one at this time and would love to continue using my Mac, but it's frustrating. Most of the time I ONLY have 1 thing open at a time, and keep my tabs down to a minimum. I bought this to do film editing on but with it acting like this I cannot do that. I know I need a ram upgrade (currently running 2 gb) and my OS is old, 10.5.8, but I think even with it being a bit outdated it should run better than this. Would a fresh install or OS upgrade resolve this? Or any other suggestions to keep this clunker chugging along for a little while longer?

    How full is the hard drive?
    Do you run any virus software or hard drive "cleaner" software like MacKeeper?
    If your model is from 2007 you can install up to 6 GBs of RAM.
    2 GBs is the barest of minimum RAM for OS X to run on.
    Especially if doing video work. You simply do not have sufficient RAM.
    Also OS X 10.5.8 Leopard support ended around 2009.
    You could update to OS X 10.6 Snow Leopard, at least.
    It is available on disc from the Apple store for U.S. $19.99.
    I Would seriously upgrade your iMac's RAM to the max. 6 GBs before doing this.
    Reliable Mac RAM can be purchase from online Mac RAM source Crucial memory or OWC ( also known as macsales).

  • My mac keeps freezing, i checked my ram fine, checked if SMART was verified it was, i reinstalled my software a few times and my RAM is 8gb used memory clean to make sure it wasnt a RAM probkem and my macbook is still freezing my RAM is 8gb i have

    My mac keeps freezing, i checked my ram fine, checked if SMART was verified it was, i reinstalled my software a few times and my RAM is 8gb used memory clean to make sure it wasnt a RAM probkem and my macbook is still freezing my RAM is 8gb i have 4.50/4.80 gb left and Mid -2012 model Macbook Pro what could be the problem also it started freezong when i upgraded to Yosemite and now my mac freezes once im logged into and sometimes has problem booting up either freezing or agent secuity error black screen??!!!!

    My mac keeps freezing, i checked my ram fine, checked if SMART was verified it was, i reinstalled my software a few times and my RAM is 8gb used memory clean to make sure it wasnt a RAM probkem and my macbook is still freezing my RAM is 8gb i have 4.50/4.80 gb left and Mid -2012 model Macbook Pro what could be the problem also it started freezong when i upgraded to Yosemite and now my mac freezes once im logged into and sometimes has problem booting up either freezing or agent secuity error black screen??!!!!

  • HT3702 Hello, I bought an itunes card since long time and i just try to use it today but massege was written that this card allready redeem  plz i need a help

    Hello, I bought an itunes card since long time and i just try to use it today but massege was written that this card allready redeem  plz i need a help

    If the card is still usable then sell it on eBay i buy us itunes card all the time from eBay,
    There is no way to make it work in the OZ Itunes store

  • Hi i purchased old booth magic with receipt No.159033112350 with the price of 3.99 but they charge me 4 time and still anytime want to use they ask me to purchase again.how i can return this extra charges to my account.

    hi i purchased old booth magic with receipt No.159033112350 with the price of 3.99 but they charge me 4 time and still anytime want to use they ask me to purchase again.how i can return this extra charges to my account.

    hi i purchased old booth magic with receipt No.159033112350 with the price of 3.99 but they charge me 4 time and still anytime want to use they ask me to purchase again.how i can return this extra charges to my account.

  • Difference between Compute lead time and Rool up lead time

    Hi All,
    Could you please clarify what is difference between Compute Lead time and Roll up lead time.
    I see in Routing > Tools.
    Thanks in Advance
    Regards
    Ravi

    Refer The Oracle document
    Manufacturing Lead Time Computations
    Manufacturing Lead Time Computations (Oracle Bills of Material Help)
    Rolling Up Cumulative Lead Times
    Rolling Up Cumulative Lead Times (Oracle Bills of Material Help)

  • Calendar travel time and places

    1. I keep my working schedule in Calendar. How can I tell Calendar that I return back home after work? With travel time activated it always calculates travel time from my office instead from my home. My office is north of my home, most private events happen south of my home, so the time difference can be as much as 30min. Work finishes at 5pm, I'm home at 5:20 and I have an event at 7pm 20min away from home. Calendar now tells me I have 40min to drive instead of just 20, because it thinks I'm still at work even though the event "Work" has ended at 5pm...
    2. Calendar does not find places even though I use the exact same phrase as it's shown in Maps. One example is the Belgian race track "Circuit de Spa-Francorchamps". I know there are work-arounds for this problem as I could just use the next town. But there are places where simply no town is around. Take the English racetrack of "Cadwell Park" for example. Typing "Cadwell Park" suggests a place in Georgia instead of the English racetrack that shows up as a POI in Maps.
    I have the same problem with a local restaurant. Again, I know where the place is, but for user comfort I'd like to have Calendar regocnize POI's shown in Maps.

    From Calendar's help:
    To set your starting location, Calendar first looks for your location in any events that are up to three hours before this event. If Calendar doesn’t find a location, it uses your work address during work hours and your home address during other hours. (Your work hours are set in Calendar preferences using the “Day starts at” and “Day ends at” menus.) If your card in Contacts doesn’t have your addresses, Calendar uses your computer’s current location.

  • Why my atv can't set time and date after restoring it using itunes ?

    when my atv restarting after  I restored it using iTunes, it can't set the time and date.
    the atv is connected to the net by wi - fi.
    when I try to sign in using my apple id, I get a massage that the password is incorrect.
    I have apple tv with ios 7.

    The network and signal test on device won't give the full picture, for that you need a network report. Go to istumbler, netstumbler or similar, that will show true signal strength as well as any nose detected. You can also try Ethernet to help rule out WiFi issues.

  • XLR and Items with leading zeros

    Forum,
    Does anyone know the best way, in XL Reporter, to deal with Item Codes that have leading zeros?
    Scenario:
    We have 2 items:  001, and 0001
    When I pull these into XLR and generate the report, Excel converts the numbers to "1"
    I have tried every cell format I can think of and have not come up with a solution.
    "Text" type returns the XLR syntax (=ixDimGet("ITM", "ItemCode")), "General" returns the "1" without leading zeros, etc.
    Anyone have a solution?
    Thanks in Advance,
    Brad Windecker

    Hi Brad,
    Seems like there's not direct solution for this one, function ixDimGet automatically removes leading zeros.
    Anyway, I would suggest that we utilize Macro Programming for this one.
    Here is a short macro code I developed, assuming the item Code is placed in Column B and the macro will automatically extract the parameter from the function call in Column B (=ixDimGet("00002") and place it Column C.
    Just place the ff code in SHEET1. The macro is utilizing the Worksheet Change event
    Const colItemCode = 2
    Const colShowCode = 3
    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Column = colItemCode Then
         strFormula = Target.Formula
         If Left(strFormula, 9) = "=ixDimGet" Then
            itemCode = Mid(strFormula, 12, Len(strFormula) - 13)
            With Range(Chr(64 + colShowCode) & Target.Row)
               .NumberFormat = "@"
               .Value = itemCode
            End With
         End If
       End If
    End Sub
    Constant colItemCode is referring to the column of the Item Code
    Constant colShowCode is referring to the column for the exracted Item Code
    Hope this help
    Laurence Resubal

  • Multi-value parameters and strings with leading zeros

    I have invoice number as a multi-value parameter. Invoice is a string,10 (VBRP.VBELN) .
    Invoice number is my group. If I enter invoices 100 and 200 as parms, then I only get data for invoice #100 (the lowest value entered). But if I enter 100, 0000000100, 200, 0000000200 as parms, then I get data for both invoices. Is there a way to get around having to enter the invoice number in both formats. BTW, if I only enter 0000000100 and 0000000200 then I get no data.
    Selection criteria is (VBRP.VBELN) = ?invoiceno --- parms are defined as allow muliple values and allow discrete values.

    Oops, that's not gonna work with multi-value parameters.  How about:
    if IsNumeric((VBRP.VBELN)) then
      ToText(Val((VBRP.VBELN)), "0") in {?invoiceno}
    else
      (VBRP.VBELN) in {?invoiceno}
    end if
    BTW, the reason why your original formula didn't work was because the "=" should have been "in".  The above is needed only if the (VBRP.VBELN) field might contain leading zeroes.
    HTH,
    Carl

  • Remove leading zeros using MDX function

    Hello,
    BO XI R3.1 SP2 FP2.5, SAP BW 7.0
    This seems simple, but I cannot find a solution.
    How do I remove leading zeros from a character field in a OLAP universe. Is there any MDX function?
    I tried
    <EXPRESSION>
    Value([0MATERIAL].[LEVEL01].[[20MATERIAL]].[Value])
    </EXPRESSION>
    <EXPRESSION>
    StrToValue([0MATERIAL].[LEVEL01].[[20MATERIAL]].[Value])
    </EXPRESSION>
    I can remove the leading zeros in Webi, but we require it for ad-hoc reporting? Is there a way to do this in the universe?
    Thanks,
    Nikhil

    Hi,
    SAP BW MDX only allows calcuated expressions that return numeric values: this is one if the main SAP MDX limitations.
    By the way there is the abilitiy to return string only for those expressions:
    [Dimension].currentmember.name
    [Dimension].currentmember.uniquename
    So you can do this:
    <EXPRESSION>
    (right([0MATERIAL].currentmember.name, 4))
    </EXPRESSION>
    <EXPRESSION>
    (right([0MATERIAL].currentmember.uniquename, 4))
    </EXPRESSION>
    <EXPRESSION>
    (left([0MATERIAL].currentmember.name, 3))
    </EXPRESSION>
    <EXPRESSION>
    (left([0MATERIAL].currentmember.uniquename, 3))
    </EXPRESSION>
    Otherwise you can use WebI formulas as described in the thread.
    Regards
    Didier

  • Code causing exceptions at its own sweet time and place

    import java.lang.*;
    class newthread implements Runnable
         Thread t;
         int click=0;
         public volatile boolean running=true;
         newthread(int p)
              t=new Thread(this);
              t.setPriority(p);
         void start()
              t.start();
         public void run()
              while(running)
                   click++;
         void start1()
              running=true;
         void stop()
              running=false;     
    class threadpriority2
         public static void main(String argv[])
              newthread ob1=new newthread(Thread.NORM_PRIORITY+2);
              newthread ob2=new newthread(Thread.NORM_PRIORITY-2);
              ob1.start();
              ob2.start();
              try
                   Thread.sleep(5000);
              catch(Exception e)
                   System.out.println("error detected:"+e);
              System.out.println("first one:"+ob1.click);
              System.out.println("first one:"+ob2.click);
              System.out.println("the priority of ob1 is:"+ob1.t.getPriority());
              System.out.println("the priority of ob2 is:"+ob2.t.getPriority());
              ob1.stop();
              ob2.stop();
              ob2.t.setPriority(Thread.NORM_PRIORITY+3);      
              ob1.t.setPriority(Thread.NORM_PRIORITY-3);
              ob1.start1();
              ob2.start1();
              ob1.start();
              ob2.start();
              System.out.println("the priority of ob1 is:"+ob1.t.getPriority());
              System.out.println("the priority of ob2 is:"+ob2.t.getPriority());
              try
                   Thread.sleep(5000);
              catch(Exception e)
                   System.out.println("error detected:"+e);
              ob1.stop();
              ob2.stop();
              System.out.println("first one:"+ob1.click);
              System.out.println("first one:"+ob2.click);
    errors during runtime:
    Exception in thread "main" java.lang.IllegalThreadStateException
    at java.lang.Thread.start(Unknown Source)
    at newthread.start(threadpriority2.java:17)
    at threadpriority2.main(threadpriority2.java:77)
    when i run this code it causes exceptions at its own sweet locations when i run it separately.if once it displays some valid input it would then be followed by the exception
    next time if i run it it will throw exception as soon as i run it at the very start without displaying even an iota of valid data like the previous case
    is ti because the os is placing restrictions on the threads growth or something else.incase there is an error in my code it should atleast pop up the exceptions at one particular loaction in the output and not give different outputs

    1) When you post code, please use and tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    wasnt aware of it.will keep it in mind i post nexttime.sorry for the inconvenience[\b]
    3) You have multiple threads, right? The scheduling of which thread gets how much CPU time when is not subject to your control or prediction, so of course you'll see different timings in subsequent runnings of the same code.[b]actually the problem is not with multiple threads showing different times.whats happening is that exceptions are being thrown randomly at runtime.once when i ran it the exception was displayed at the very beginning of the output and the program snapped.next when i ran it first some output which was slated to be displayed got displayed and then the exceptions appeared in the output.now if the exceptions are thrown at the very beginning its obvious theres some problem at the background coz in the second case that never happened[\b]
    i guess the formatting tips have taken effect[:D]

Maybe you are looking for