6 Replies Latest reply on Jul 17, 2008 8:37 AM by velvet2

    GetFieldValue() to read a DateTime value

    649697
      How can I use the function GetFieldValue() to read a DateTime value in a table field and then convert it to a string ?

      Mario
        • 1. Re: GetFieldValue() to read a DateTime value
          velvet2
          I do the conversion on server side which resolves this problem
          • 2. Re: GetFieldValue() to read a DateTime value
            649697
            And how can I make it if I can only access the table using c++ ?
            • 3. Re: GetFieldValue() to read a DateTime value
              velvet2
              If You have access to query texts
              write "to_char(someday, 'dd/mm/rrrr')" instead of writing "someday"

              If You don't - contact Your DBA or database developer to rewrite sqls

              then use
              oresult GetFieldValue(int index, char *buffer, unsigned short maxlen) const                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
              • 4. Re: GetFieldValue() to read a DateTime value
                649697
                I have tryed with:

                odyn.Open(odb, "select * TO_CHAR(PERIOD_END_DATE, 'DD/MM/YYYY HH:MI:SS' from my_table", ODYNASET_NOCACHE | ODYNASET_READONLY);
                but it doesn't work.

                I have olso tryed with odyn.SetSQL() followed with odyn.Refresh() but always not to do, if I read the SateTime field in a char string or in an int its value is always wrong.

                Mario
                • 5. Re: GetFieldValue() to read a DateTime value
                  649697
                  Tank you for the help velvet2, I have found the solution by myself and it is:

                  struct tm *m_t;
                  long mm_period_end;
                  odyn.GetFieldValue("scheduled_date", &mm_period_end);
                  time_t t = mm_period_end;
                  time( &t );
                  m_t = localtime( &t );     // Convert time to struct tm form
                  char ss[50];
                  sprintf_s( ss, "%s", asctime( m_t ) );
                  int dd = m_t->tm_mday;
                  int mm = m_t->tm_mon + 1;
                  int yy = m_t->tm_year + 1900;
                  etc.
                  etc.

                  bye,
                  Mario
                  • 6. Re: GetFieldValue() to read a DateTime value
                    velvet2
                    select * TO_CHAR(PERIOD_END_DATE, 'DD/MM/YYYY HH:MI:SS' from my_table

                    This is not valid sql query
                    Valid examples are:

                    select TO_CHAR(PERIOD_END_DATE, 'DD/MM/YYYY HH:MI:SS' from my_table

                    select t.*, TO_CHAR(PERIOD_END_DATE, 'DD/MM/YYYY HH:MI:SS' from my_table t