Remove Characters from a Date

What are some ways that I could remove the hyphens, semicolons, periods, and empty strings from a date (in a single expression)?
If I have a date (returned from GETDATE()) as follows:
2014-09-15 16:53:09.253
I want to remove the non-numeric characters and return this:
20140915165309253
Can REPLACE be used to identify more than one character pattern to replace?
Thank you for your help!
cdun2

Another way, don't remove at all, begin with just the requisite dateparts and datenames. Although either way works fine, this way gives you absolute control over how you render.
In this example, the "from sys.messages" is not part of the answer, I just included it to recreate a test to compare speeds.  It ends up having the same speed/execution plan/actual CPU time used either way. 
The "Right()" functions are required, because for example, if the time is 8:03, the "03" is presented as just "3", so you have to force it to render as "03" with the Right function.  The DatePart(month) is the
only one returning an integer result, so that must be cast as Varchar, the DateName() functions return a string, although unfortunately with leading zeroes removed.
Select Datename(year, SysDateTime())
+ Right('0' + Cast(DatePart(month, SysDateTime()) as varchar(2)) , 2)
+ Right('0' + DateName(day, SysDateTime()), 2)
+ Right('0' + DateName(hour, SysDateTime()), 2)
+ Right('0' + DateName(minute, SysDateTime()), 2)
+ Right('0' + DateName(second, SysDateTime()), 2)
+ Right('0' + DateName(ms, SysDateTime()), 3) , sysdatetime()
from sys.messages sm1
Select REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(30), GETDATE(), 121),'-',''),':',''), '.',''),' ',''), sysdatetime()_
from sys.messages sm1

Similar Messages

  • Removing characters from an input data-field

    Hi.
    Is it possible to "Trim Off" characters from a Text Field data, and automatically input them into another Text field?
    Let's say I have the following code :
    *<Field name='telephonenumber'>*
    *<Display class='Text'>*
    *<Property name='title' value='Phone Number in International Format'/>*
    *<Display>*
    *</Field>*
    This code is to input the telephone number in International Format (such as :  +1 234 567 8900)
    Now, lets say that I want to create a second Data Text field for phone number; but, this time, it is for the phone number in LOCAL format.
    In other words, I want to write a code which will AUTOMATICALLY  remove the first 3 or 4 characters from the "International Number",  and input them into the "Local Number"  field.
    This would save me the trouble or writing the number a second time. My code should be able to simply Trim Off the initial "+1 234", and automatically input the remaining "*567 8900"* into the Local Number field.
    How could I accomplish this?
    Thanks

    Based on your code, it looks like you have fields called global.workgsmad (local style) and global.workgsm (international style)
    Assuming your global.workgsm format will always be '+x xxx xxx xxxx' you want to skip the first 6 characters, not 4
    The simplest way to do this is like so:
    <Field name='global.workgsmad'>
       <Expansion>
          <substr>
             <ref>global.workgsm</ref>
             <i>6</i>     <!-- Skip the country code and area code '+x xxx ' -->
             <i>8</i>   <!-- 8 characters were left for the format 'xxx xxxx' -->
          </substr>
       </Expansion>
    </Field>Alternatively, you could change the substr block to read
    <substr s='6' l='8'>
       <ref>global.workgsm</ref>
    </substr>Both formats are valid.
    If the phone number is not a fixed format, you'll have to do something more complicated.
    Jason

  • Remove special characters from incoming data

    Hi Varun, You could use either of below.. REG_REPLACE(YOUR_INPUT_STR,^[A-Za-z0-9 ],NULL)  -- Replaces all non-alphanumeric with null
       REG_EXTRACT(YOUR_INPUT_STR,[A-Za-z0-9 ]) -- Extracts only alphanumeric data -Rajani

    i have special character coming in the source data and i want to remove it before loading into target, currently i am getting one special character , it may come as some other type of special character  other than alpha numeric. so how to remove those special characters from data and load the alphanumeric data into target.

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • Remove $%&* characters from a String

    Hi,
    I have the following program that is supposed to detect a subsequence from a String (that contains $ signs) and remove it. This is a bit tricky, since because of $ signs, the replaceAll method for String does not work. When I use replaceAll for removing the part of the String w/ no $ signs, replaceAll works perfectly, but my code needs to cover the $ signs as well.
    So far, except for replaceAll, I have tried the following, with the intent to first remove $ signs from only that specific sequence in the String (in this case from $d $e $f) and then remove the remaining, which is d e f.
    If anyone has any idea on this, I would greatly appreciate it!
    Looking forward to your help!
    public class StringDivider {
         public static void main(String [] args)
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
             String removeSymbols = "$d $e $f";
             int startIndex = symbols.indexOf(removeSymbols);
             int endIndex = startIndex + removeSymbols.length()-1;
             for(int i=startIndex;i<endIndex+1;i++)
                  if(symbols.charAt(i)=='$')
                       //not sure what to do here, I tried using replace(oldChar, newChar), but I couldn't achieve my point, which is to
                       //delete $ signs from the specific sequence only (as opposed to all the $ signs)
             System.out.println(symbols);
    }

    A little modification on the last version:
    This one's more accurate.
    public class StringDivider {
         public static void main(String [] args){
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
                  String removeSymbols = "$d $e $f $g";
                  if(symbols.indexOf(removeSymbols)!=-1)
                       if(removeSymbols.indexOf("$")!=-1)
                            removeSymbols = removeSymbols.replace('$', ' ').trim();
                            removeSymbols = removeSymbols.replaceAll("[ ]+", " ");
                            String [] symbolsWithoutSpecialChars = removeSymbols.split(" ");
                            for(int i=0;i<symbolsWithoutSpecialChars.length;i++)
                                 symbols = symbols.replaceAll("[\\$]*"+symbolsWithoutSpecialChars, "");
                             symbols = symbols.replaceAll("[ ]+", " ");
                   else
                        symbols = symbols.replaceAll(removeSymbols, "");
              symbols = symbols.trim();
              System.out.println(symbols);

  • Re: remove special characters from incoming data

    Dear Varun Kumar, Please use this logic. REG_REPLACE(INPUT FIELD,'[^A-Za-z0-9]' ,'')Only Characters and Numbers it will come. I Tried Same Logic it working. Please let me Know. Thanks & RegardsKasireddy+966545281845

    Hi Varun, You could use either of below.. REG_REPLACE(YOUR_INPUT_STR,^[A-Za-z0-9 ],NULL)  -- Replaces all non-alphanumeric with null
       REG_EXTRACT(YOUR_INPUT_STR,[A-Za-z0-9 ]) -- Extracts only alphanumeric data -Rajani

  • Removing characters from a String

    Hi!
    I have a large String that has some unwanted characters in it that I want to remove. Here is an example:
    AA1lbmNvZGVkUGFy\015\012YW1zdAACW0JbABBlbm5MQ2Is there any method I can use to remove the characters \015\012 from the String. I looked at the method String.replace(char, char); but this is unsuitable because I can only remove one charater at a time an I may have this character occuring legitimately elsewhere in my String. Would it be possible in some way to traverse the String and identify the pattern of \015\012 and remove that.
    I'd appreciate any help,
    Thanks
    Chris

    Specifically,  str = str.replaceAll("\\\\01[25]", "");The replaceAll method is only available in v1.4.0 or later.

  • Remove characters from rightside

    In my query I select the following table
    ,pa_expenditure_items_all.ORIG_TRANSACTION_REFERENCE.
    The output gives values like
    12567245:2
    12567244:2
    12567247:3
    9367349:2
    9367349:4
    I would like to remove the last two positions in this output.
    However this proves to be, for me, more difficult then expected.
    The total number of characters varies so i can't use SUBSTR with counting starting from the left side.
    I tried REPLACE and TRIM but didn't get it right.
    Hope someone can help my out on this.

    Several methods are available:
    WITH pa_expenditure_items_all AS (SELECT '12567245:2' orig_transaction_reference
                                        FROM dual
                                       UNION
                                      SELECT '9367349:23'
                                        FROM dual
                                       UNION
                                      SELECT '79367349'
                                        FROM dual
    SELECT orig_transaction_reference
         , SUBSTR(orig_transaction_reference
                 ,1
                 ,DECODE(INSTR(orig_transaction_reference, ':')
                        ,0, LENGTH(orig_transaction_reference) + 1
                        ,INSTR(orig_transaction_reference, ':')
                        ) - 1
                 ) new_val_v1
         , REGEXP_SUBSTR(orig_transaction_reference
                        ,'^[^:]+'
                        ) new_val_v2            
      FROM pa_expenditure_items_all
    ORIG_TRANS NEW_VAL_V1 NEW_VAL_V2
    12567245:2 12567245   12567245
    79367349   79367349   79367349
    9367349:23 9367349    9367349C.

  • Remove quotes from the data when building rule file

    I get double quotes in one of the field in the file. e.g. Part descirpiton as inches. I have to join part number and part descrption to create one field and create level 0 dimension. When I try to replace " with space after joining the two fields, it does not replace the quotes. If I replace it first and then join the fields, it gives me error "The field type for this field is not valid for the build method associated with this field's dimension."
    What am I doing wrong?
    Thanks
    Please help.

    A double quote is one of the problem children of Essbase. If this is coming in from SQL, you could do a replace on the character to remove it. If it is a flat file, if it is always in the same location, you could split the field on the character and ignore it. It has been a long time since I've had to deal with the problem, but I think I ran my file through some preprocessing to remove it.

  • Removing characters from string after a certain point

    Im very new to java programming, so if this is a realy stupid question, please forgive me
    I want to remove all the characters in my string that are after a certain character, such as a backslash. eg: if i have string called "myString" and it contains this:
    109072\We Are The Champions\GEMINI
    205305\We Are The Champions\Queen
    4416\We Are The Champions\A Knight's Tale
    a00022723\We Are The Champions\GREEN DAYi would like to remove all the characters after the first slash (109072*\*We...) leaving the string as "109072"
    the main problem is that the number of characters before and after is not the always the same, and there is often letters in the string i want, so it cant be separated by removing all letters and leaving the numbers
    Is there any way that this can be done?
    Thanks in advance for all help.

    You must learn to use the Javadoc for the standard classes. You can download it or reference it on line. For example [http://java.sun.com/javase/6/docs/api/java/lang/String.html|http://java.sun.com/javase/6/docs/api/java/lang/String.html].

  • Remove characters from phonenumbers

    Hello,
    I have the following problem:
    35% of the phonenumbers in my contacts contain a wrong phone number format.
    Some phonenumbers in my contacts contain a format like +<country code> (0)<area code> phonenumber  or (+<country code> <area code>)<phonenumber> or (<areacode>)<phone number>
    Because the numbers are formated with ( ) and - i have problems with my bluetooth device when dailing from my addresbook/contacts
    I want to remove the (0) from all the phone numbers and all other illegal charactars so the format will be like this:
    +<country code> <areacode> <phonenumber>
    I tried the Mac App Contacts Cleaner but this app does not reconize the current format and can not translate to my required format.
    So i have to edit 200 contacts by hand.
    Please advice.
    Thanks

    Try this:
    $iscsitarget = Get-EqlVolume -VolumeName TZ | select -ExpandProperty iSCSITargetName

  • Removing Encyption from cloud data

    During the provider installation section for VMM Server, I enabled encryption.  I know wish to remove this.  What is the least invasive way to do this?  (I would like to do it without having to start from the beginning).  Also, is it
    possible to setup one set of protected vms as encrypted and another as not?

    Hello Johnny,
    Are you referring to selecting the below check box during the registration process? (See
    here)
    If the answer is yes, then you have nothing to be really worried about. All you did by selecting that check-box is that you created a Encryption Key that can be used to encrypt VMs that are replicating to Azure. This does not mandate all VMs that get protected
    to Azure from this VMM Server will be Encrypted.
    So the question now becomes what is that setting that turns on encryption for replicating VMS?
    The answer lies in Cloud Pairing, and here is how you go about doing it
    1) Log into the portal & browse to your Vault.
    2) Under the protected items in the vault, select the cloud you want to protect to Azure.
    3) In the configuration tab, select Microsoft Azure as the Target Once you do this you will something very similar to
    this screen
    4) Slide the Encryption At Rest slider to ON position to enable encryption for all VMs under that cloud.
    5) Post this configuration, all VMs that are a part of this cloud and get enabled/added for protection will be encrypted and stored in your azure storage account till the time of failover.
    6) At failover time you will need to provide the Certificate (encryption key) that was generated during registration to decrypt the VMs and allow them to failover in Azure.
    Please Note: If you choose to switch on Encryption At Rest settings during cloud pairing, then all VMs that will are protected under that cloud will be encrypted.
    About your second question as long as the VMs are grouped into separate clouds, you can choose which clouds to encrypt and which not to.
    Hope that helps!
    Anoop KV
    This posting is provided "AS IS" with no warranties, and confers no rights

  • How to remove body from JMS data In OSB?

    Hi
    I am puttting xml type of data in a queue but the data is coming with body tag. My requirement is to place payload only in JSM queue without soap body.
    Steps i followed are;
    1. Created business service with
    Service Type      Messaging Service
    Request Message Type XML      
    2. Created proxy service with
         Replace [ entire node ] of [ . ] in [ body ] with [ $body ]
    How to do that?
    Thanks
    Vibhor

    Are you using the OSB test console to post the message?Have you ensured there is no <body> tag in the input?
    I have checked what I have pasted above and it is working fine!
    Thanks,
    Prabu

  • How to remove spikes from a data channel

    We wrote a module in DIAdem to look at each single point and used some logic to determine if it is a spike or not. If it is we replace it with the mean of neighbouring points.
    BUT this takes a long time for big data channels
    Is there a routine which does it faster/quicker

    Hi,
    A Formula using complete channels is much faster than a formula using a
    loop over all values. Of course it depends on the logic you are using.
    Here is an example for everything over 10 is a spike:
    Call FormulaCalc("Ch('A'):= Ch('A') + (Ch('A')>10)*Novalue")
    This Formula declares every value above 10 to Novalue. Using logical
    coparissons in channel calculations can be a very helpfull in many
    cases.
    Now you can use the math function for novalue handling to replace every novalue thru interpolation.

  • Fetching international characters from Clob

    Hi,
    I am trying to fetch hungarian characters from Clob data. I tried reading the Character Stream returned by Clob.getCharacterStream() in linux and it returns junk characters for those but the same works well with windows. I guess its picking up the platform depended default charset. Is there any way i can get the characters without changing the default charset of the OS ? any other way would be highly appreciated!
    Thanks in advance.

    Hi,
    I am trying to fetch hungarian characters from Clob
    data. I tried reading the Character Stream returned
    by Clob.getCharacterStream() in linux and it returns
    junk characters for those but the same works well
    with windows. Are you printing it to the console window on the OS to determine this?
    Then you are doing it incorrectly. That process of outputing a string requires mapping characters to the console character set.
    The only correct way to do this is to print the numeric representation of each character and see if that is correct. If it is correct then it is not a JDBC/driver problem. If it is not correct then it is a JDBC/driver problem.

Maybe you are looking for