Display dates with zeros for month, day, year.

I have a date coming from a database as an int (20021215 means 12/15/2002). If the database gives me a "0", meaning no date value is assigned, then it should be displayed as "00/00/0000". The following code snippet works for the non-zero int database values ...
public static String formatDisplayDate(int date) {
    String dateAsString = null;
    if (date == 0) {
        dateAsString = "00000000";
    else {
        dateAsString = Integer.toString(date);
    String strYear = dateAsString.substring(0,4);
    String strMonth = dateAsString.substring(4,6);
    String strDay = dateAsString.substring(6);
    int year = Integer.parseInt(strYear);
    int month = (Integer.parseInt(strMonth)) - 1;
    int day = Integer.parseInt(strDay);
    DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
    Calendar cal = myFormat.getCalendar();
    cal.set(year, month, day);
    Date myDate = cal.getTime();
    String formattedDate = myFormat.format(myDate);
    return formattedDate;
}Although I didn't really expect the zero values case to work, I am not sure how to implement it. How would I go about building a string using all zeros and still have it automatically display in the correct locale format?
Any help is appreciated.

Thank you for your response. I agree a blank field would be better, but I think the "zeros" format is there to give the user an idea of expected date entry formatting, not that they'll necessarily follow it. I have made a few changes per your suggestions (shown below for the record, minus the exception handling), and it works perfectly.
public static String formatExternalDate8(int date) {
  String dateAsString = null;
  if (date == 0) {
    dateAsString = "00010101";
  else {
    dateAsString = Integer.toString(date);
  int year = Integer.parseInt(dateAsString.substring(0,4));
  int month = (Integer.parseInt(dateAsString.substring(4,6))) - 1;
  int day = Integer.parseInt(dateAsString.substring(6));
  DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
  Calendar cal = myFormat.getCalendar();
  cal.set(year, month, day);
  Date myDate = cal.getTime();
  String formattedDate = myFormat.format(myDate);
  if (date == 0) {
    formattedDate = formattedDate.replace('1', '0');
  return formattedDate;
}Thanks again for your assistance.

Similar Messages

  • Can I change the day/date format from US (month day year) to UK (date month year)?

    When I view databases through Firefox, the date/day format is set at month, day, year (US style), whereas I need day, month, year, I work in the UK and the "wrong" format is VERY confusing and could lead to errors/mistakes. IE has that format but I don't want to revert to using that.

    Gingerbread Man, thank you VERY much!! I followed your instructions and it works perfectly. I am a happy person :-))

  • Data element for Month and Year

    Hello All,
    Is there any data element which will have only Month and Year.
    I have to introduce this field in a table. It should have convesion exits also.
    Ex: If i give 092009, it sould come like 09.2009
    Thank you.
    Best Regards,
    Sasidhar Reddy Matli.

    Kindly Try this code for Month and year as input and having standard F4 help..
    INCLUDE RMCS0F0M.
    TYPES : BEGIN OF TY_SELECT,
              MONTH TYPE FTI_MONTH_YEAR,
            END OF TY_SELECT.
    DATA : WA_SELECT TYPE TY_SELECT.
    SELECTION-SCREEN : BEGIN OF BLOCK SANDEEP WITH FRAME.
      SELECT-OPTIONS : S_MONTH FOR WA_SELECT-MONTH OBLIGATORY NO INTERVALS NO-EXTENSION.
    SELECTION-SCREEN : END OF BLOCK SANDEEP.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MONTH-LOW.
      PERFORM MONAT_F4.
    SANDEEP JAIN

  • Date Format Conversion MM/DD/YYYY to Month Day, Year

    Hi all,
    Is there a function in BIP that converts MM/DD/YYYY to Month Day, Year?
    eg.
    10/08/2010 convert to October 08, 2010
    Thank you very much!

    Since your date is not in canonical format, you cant format dates directly.
    You need to get it done with workarounds.
    Try using
    <?xdoxslt:month_name(substring(DATE,1,2), 0, $_XDOLOCALE)?> <? substring(DATE,4,2)?>, <? substring(DATE,7,4)?>
    Here I assume your date comes in the format MM/DD/YYYY

  • My Samsung SE-S084F dvd burner, used with lion for months is now suddenly unsupported. Why?

    My Samsung SE-S084F dvd burner, used with lion for months is now suddenly unsupported... how can it be possible? I can now read cd/dvd but trying to burn them gives me "Internal error". Disk Utility report: "Burn support: not supported".
    I burned my last dvd three days ago, running lion 10.7.3. The only thing I can think of is a software update done few days ago, something about java.
    Samsung says that lion isn't officially supported, but i've used it a lot and I know it works…
    Things that i've tried:
    1) reboot
    2) firmware update
    3) many different burning software including "drutil" from the shell
    4) I've tested the device on another computer (ubuntu 11) and it works like a charm
    Additional information (drutil info):
    Vendor          Product                          Rev
    TSSTcorp      CDDVDW SE-S084F      TS00
    Interconnect: USB
    SupportLevel: Unsupported  
    Profile Path: None
    Cache: 1536k
    CD-Write: -R, -RW, BUFE, CDText, Test, IndexPts, ISRC
    DVD-Write: -R, -R DL, -RAM, -RW, +R, +R DL, +RW, BUFE, Test
    Strategies: CD-TAO, CD-SAO, CD-Raw, DVD-DAO
    Any tips? Thanks.

    Adding other info, it's getting even more weird...
    I've tried booting from an old snow leopard backup, and surprise... the devise still doesn't work!!! same error!
    It doesn't make any sense...
    It's not broken but both SL and Lion on my MBP refuse to burn DVDs (they both burned a lot of them with that device in the past).
    Same thing using the other USB burner borrowed by a friend, so i'm sure it's not a cable problem... what does remain? Mac's USB hardware failure? Impossible. On my SL backup there was installed Parallels desktop with an old ubuntu virtual machine configured, i've tried burning from it and it worked...
    OSX (LS or Lion) + My MBP + USB Burner = fail
    Ubuntu + My MBP + USB Burner = success
    Ubuntu + Another computer + USB Burner = success
    The could be some "broken" low level hardware bounded parameters, used only by OSX. I've already wiped NVRAM and PRAM, are there any other things i can try to wipe?

  • Getting all dates of a particular month and year

    I want to get list of all dates of a particular month and year .
    How to get using Calendar List?

    Create a Calendar object. Set it's month and year. Then call getActualMaximum(Calendar.DAY_OF_MONTH); on the Calendar object. That will tell you how many days are in the month of that year.

  • Delivery Date with Zero Order Quantity in Sales Order

    Dear All,
    I have created a sales order in va01 with different delivery date in schedule lines. I want to save delivery date with zero order
    quantity because he has not delivery on time.

    Dear All,
    I have created a sales order in va01 with different delivery date in schedule lines. I want to save delivery date with zero order
    quantity because he has not delivery on time.
    Deatils :
    Delivery Date     Order Quantity  Delivery Qty
    02.09.2011       10                    10
    05.09.2011       10                    10
    09.09.2011       10                    10
    15.09.2011       10                    10
    21.09.2011       10                    0
    Now i want to insert a new schedule line 10.10.2011 with order quantity 10. or 21.10.2011 schdeule date with 0 quantity.
    Presently system can't save schdeule date 21.09.2011 with o quantity.

  • Leading zeros for Month and Day in filename.

    Hello,
    I am in Jdev 10.1.3.3.0
    One of my requirement is to have a file name concatenated with current month and day (example: <filename><02><23>).
    Used the xpath as following and returns an output as *'filename223'*:
    concat('filename',xp20:month-from-dateTime(ora:getCurrentDate()),xp20:day-from-dateTime(ora:getCurrentDate()),'.txt')
    what changes I need to make in my Xpath to get the file name as *'filename0223'*
    Thanks in advance!
    Regards,
    Rakesh

    I was googling on the date format used in BPEL to achieve various format types. Specially I was searching for my requirement : <filename><current month with leading zeros if month is single digit><current day with leading zeros if day is single digit>(ie. if the month is february and day is 23rd, then my filename should be *<filename><02><23>*).
    I found a link which helped solving my problem :
    http://plane.javaeye.com/blog/161316
    I changed my Xpath to :
    concat('filename',xp20:format-dateTime(ora:getCurrentDate(),'[M01][D01]'),'.txt')
    And I got my expected result : *'filename0223.txt'*
    Regards,
    Rakesh

  • Extracting data with zero values for periods without data

    Hello Together,
    i extracted data from our hfm application from period 1 to 3.
    Now i found that some rows begin with period 2 or 3 because there are no data in period 1 or 2.
    So my question is, how i can get zero values for periods with no data.
    Hope someone can help me.
    Many thanks in advance.
    Martin
    P.S.: Our actual hfm version is 11.1.1.3
    edit

    For the periods with no data, HFM does not have a "0" to offer for the data extraction. Since the default data extract from HFM has each period on it's own row in the *.dat file, I don't understand your comment about rows starting with period 2 or 3. In the *.dat file the row for period 1 simply won't exist. Are you using a custom approach/tool for data extraction?
    The only time HFM will offer a "0" where there is indeed no data, is if you extract derived data. You must include calculated data, and even then I believe HFM will only extract a "0" for the first period after a period where there was data, and only for flow accounts (Revenue/Expense). so if you have "100" in period 1, and no data in period 2, such that the derived value YTD for period 2 is "0", then you must include calculated values in the extract and you should see "0" for period 2. However, I don't believe HFM will extract "0" for period 3 - instead it will be blank/missing.
    In general it could be very dangerous to force HFM to give zeros where there is no data.
    --Chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to set filter criteria for month and year using in timestamp input field?

    Hi,
    I am using jdev 11.1.2.3,
    I have one problem with Report generation,,,,,,I have one report table which is in the form of VO(query based) and i want to search this table as month and year basis
    but in this table(query) that field having timestamp based value.. how to search with month name and year only.. Here i am using totally query base VO's for generating
    reports........ Can any one guide me.
    Thank You.

    You can use a inputdate, which allows you to selecte a moth, year and a day. Once the selection is made you convert it to only allow moth and date like
            <af:inputDate label="Label 1" id="id1" autoSubmit="true" value="#{bindings.myMonthYear1.inputValue}">
              <f:convertDateTime pattern="MM/yyyy"/> 
            </af:inputDate>
            <af:outputText value="Selected #{bindings.myMonthYear1.inputValue}" id="ot1" partialTriggers="id1"/>
    then you have a string holding month and year only. This value you split into two variables you or pass it as a whole parameter to the query and split it there.
    Another way is to add two static lovs one for month and one for year and use them to get to the filter values.
    Timo

  • Date Picker: Only select Month and Year

    Hallo,
    I try to configure the Date Picker. For the users it should only be possible to select Month and Year. The column should be automaticly completed with the first day of the select month and a static time (00:00:00).
    How can I do this?
    Sincerly

    You can't do that with a standard date picker. What you could do is to use it and after you change the value in it you modify the value using javascript and ajax similar to what I do in this example:
    http://htmldb.oracle.com/pls/otn/f?p=31517:9
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • I need help! My iPad2's stubbornly showing the wrong month, day, year and time.

    This happened after I updated my new iPad2 to the iOS 5.0.1. The calendar shows a date way ahead into the future. Ex. Today is Dec. 31, 2011, 6am, Manila time but its showing Jan. 1, 2555 BE, 8am. It just got my location right. I tried resetting it at Settings but it keeps on going back to the wrong date, 2555 BE. I turned off the automatic update, and manually set the time, but It seems to insist the error. I sync this iPad with iTunes to a Windows 7 PC, it has the correct date, year and time zone. I've been following a similar thread here but I could not find it now. Please give advice that I could do on my own first before I seek Apple care coz its almost party time here. Thanks and Happy New Year!

    I got several advice from other Apple users such as: restart the iPad by pressing the home button and the sleep/wake simultaneously, turn off the auto-update of date and time, make sure it's in Gregorian, sync with a computer with the right date and time and restore. I did all of the above except restore but it didn't help. I thought I should restore to the previous iOS. When I tried to restore, I learned that it'll still be in iOS 5.0.1, and since I also couldn't back up to iCloud (which freaked me out), I chickened out of it and called the nearest Apple Store. They were very kind to help me for  free.
    Before I went to the store, I backed up my iPad to PC first to keep my paid apps at least. Then the Apple guy checked the problem himself and he restored it in their iTunes. After the restore, the month, day, time and year were correct. When I got home, I just synced with the previous back-up. All my apps were re-installed, my games were intact but my documents saved in some apps (like Documents to Go, PDF Expert and CHM+) were gone.
    The Apple guy said, I might have encountered an Internet problem while I was updating hence the bug. I was the first case they've encountered. But they couldn't explain what the BE stands for... Before Extinction? Hope the experts shed light on this to avoid it coz I wasn't able to use my iPad or even back-up to iCloud.

  • Displaying no default zeroes for the numeric field in the table display.

    hi folks,
         I am binding a table in the context which has some numeric fields. I'm  displaying the same table which has some records for editing purpose. But the problem is that the numeric  field column is being displayed with zeros if it doesnot have any value in it. Can u explain how to disable the zeroes by not displaying them by defualt when there is no value for the numeric field.
    regards,
    Ramu

    set the format of the context attribute TEST is the context attribute name
    data: lr_info type ref to if_wd_context_node_info.
    data: ls_prop type WDY_ATTRIBUTE_FORMAT_PROP.
    lr_info = wd_context->get_node_info( ).
    ls_prop = lr_info->GET_ATTRIBUTE_FORMAT_PROPS( name = 'TEST' ).
    LS_PROP-NULL_AS_BLANK = 'X'.
    lr_info->sET_ATTRIBUTE_FORMAT_PROPS( name = 'TEST'
                 FORMAT_PROPERTIES = ls_prop ).
    Abhi

  • SELECTION SCREEN FIELD FOR MONTH AND YEAR

    Hi All.
    We are developing a 'Monthly Sales Tax(payable) Report.
    they want the report based on the date(in the selection screen it will come only month and year only.).Depends on that month and year for that select-options ,it will pick up the record.
    like if, jan 2005  to march 2006.
    then it will  pick up from 01.01 .20005 to 31.03.2006  records.
    Can any body help me to resolve this.
    Thanks in advance,
    Regards,
    Venkat

    Hi Venkat,
    Copy the following code.
    DATA :  ws_billfrom    TYPE dats,
            ws_billto      TYPE dats.
    DATA : mon TYPE fcltx.
    SELECT-OPTIONS: s_month FOR mon
                MATCHCODE OBJECT zsdhtch_sh_mnth
                OBLIGATORY. "o get values for F4
    PARAMETER :  p_year LIKE bkpf-gjahr
                 MATCHCODE OBJECT zsdhtch_sh_year
                 OBLIGATORY.
    RANGES : s_date FOR sy-datum.
    DATA : ws_fcmnr TYPE fcmnr.
    START-OF-SELECTION.
      SELECT SINGLE mnr
             INTO ws_fcmnr
             FROM t247
             WHERE ltx = s_month-low.
      CONCATENATE p_year ws_fcmnr '01' INTO ws_billfrom.
      CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
           EXPORTING
                iv_date             = ws_billfrom
           IMPORTING
                ev_month_begin_date = ws_billfrom
                ev_month_end_date   = ws_billto.
      s_date-low = ws_billfrom.
      s_date-high = ws_billto.
      s_date-sign = 'I'.
      s_date-option = 'BT'.
      IF NOT s_month-high IS INITIAL.
        SELECT SINGLE mnr
               INTO ws_fcmnr
               FROM t247
               WHERE ltx = s_month-high.
        CONCATENATE p_year ws_fcmnr '01' INTO ws_billfrom.
        CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
             EXPORTING
                  day_in            = ws_billfrom
             IMPORTING
                  last_day_of_month = ws_billto.
        s_date-high = ws_billto.
      ENDIF.
      APPEND s_date.
      WRITE s_date.
    You can write your select statement here.  
      select * from dbtable where date in s_date.
    If 'HR_JP_MONTH_BEGIN_END_DATE' is nto there in your server, you can use 'RP_LAST_DAY_OF_MONTHS' in both cases.
    Regards,
    Susmitha.
    Dont forget to reward points for  useful answers

  • F4 option for Month and Year

    hi
    In Selection Screen i have Month and Year as input.....
    How to give "F4" Option for both Month and Year?
    Regards
    Smitha

    hi,
    this will help u get the month in f4 help .
    similarly u can fill up the itab for year and get that f4 help too i guess.
    TABLES: T247 ,
            DFIES.
    PARAMETERS:P_MONTH LIKE T247-MNR.
    DATA: BEGIN OF ITAB OCCURS 0,
    MNR LIKE T247-MNR,
    KTX LIKE T247-KTX,
    END OF ITAB .
    DATA : LT_FIELDS TYPE TABLE OF DFIES,
           LWA_FIELD TYPE DFIES.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_MONTH.
      SELECT MNR
             KTX
      FROM T247 INTO CORRESPONDING FIELDS OF TABLE ITAB
      WHERE SPRAS = 'EN'.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD    = 'P_MONTH'
          DYNPPROG    = SY-CPROG
          DYNPNR      = SY-DYNNR
          DYNPROFIELD = 'MNR'
          VALUE_ORG   = 'S'
        TABLES
          VALUE_TAB   = ITAB
          FIELD_TAB   = LT_FIELDS.

Maybe you are looking for

  • Files on Memory Card

    I am deleting unwanted files and programs from my Memory Card. There are some names having large files  i am not familiar with. MSG-m1 MSG-m1b MSG-m2 MSG-m4 & m4b NASB module 1 & 1F NASB Module 2 &2F  NLT-m1 - m4 I cant figure what they are associate

  • Planning Level and Planning Group empty

    Hello We have recently activated EA-FIN (Financials Extension) in our client´s SAP system (ECC 6.0) to implement Liquidity Planner via transaction SFW5. After this activation, we found that SAP is not updating fields of planning level (FDLEV) and pla

  • Early watch Alert in Solution Manager 7.1

    Hi All Are there any sap reference guides on configuring Early watch on Solution Manager 7.1? I tried looking this up in help.sap with little luck. We have installed Early watch 7.1 and have run solman_setup till the Basic Configuration phase (with s

  • Repeating pop-up for Adobe flash

    Since approx 2 weeks, everytime when I start Explorer 10 (windows 7), a pop-up appears asking me if I want to install Adobe flash. This pop-up directs to a file named swflash.cab. I already installed Adobe flash (version 11.8) on my computer and what

  • Workflow - Monotoring Approval

    Hi, I have a situation that, a user in SRM approved a "shooping cart" by email (which is   normal, only if they want to check all the items they can login in SRM). The question is..  is it possible to see in WF Log or, tr. SOST, etc, if this "shoopin