year to date conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgxbytes
    New Member
    • Sep 2008
    • 25

    year to date conversion

    hi ,

    i have a string sYear = 2008;
    i need search from the database the results which are in the year 2008.

    so how can i convert 2008 to this format

    sDateFrom = "2008-01-01";
    sDateTo = "2008-12-31";

    thanks in advance...
    raj
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by sgxbytes
    hi ,

    i have a string sYear = 2008;
    i need search from the database the results which are in the year 2008.

    so how can i convert 2008 to this format

    sDateFrom = "2008-01-01";
    sDateTo = "2008-12-31";

    thanks in advance...
    raj
    If you just want String representations of the first and last day of the year you can
    do this:

    Code:
    int year= ... ;
    String sDateFrom= year+"-01-01";
    String sDateTo= year+"-12-31";
    Otherwise have a look at the (Gregorian)Cale ndar class.

    kind regards,

    Jos

    Comment

    • N002213F
      New Member
      • Sep 2007
      • 38

      #3
      Most DBs now support date parsing in the queries. Some to_char for Oracle. check DB documentation as well.

      Comment

      Working...