Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. c++ win32 , equivilent to DateTime.Now() in asp.net

c++ win32 , equivilent to DateTime.Now() in asp.net

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++asp-netdatabasesql-server
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    Is there an equivilent to the DateTime.Now() in asp.net, I'm writing a time stamp to sql server, and wanted to keep the same format.

    dbUA->pzDateOpened = some sort of DateTime.Now();

    C S L 4 Replies Last reply
    0
    • J jkirkerx

      Is there an equivilent to the DateTime.Now() in asp.net, I'm writing a time stamp to sql server, and wanted to keep the same format.

      dbUA->pzDateOpened = some sort of DateTime.Now();

      C Offline
      C Offline
      Chandrasekharan P
      wrote on last edited by
      #2

      GetCurrentTime() function should work for you. [^]

      Every new day is another chance to change your life.

      J 1 Reply Last reply
      0
      • J jkirkerx

        Is there an equivilent to the DateTime.Now() in asp.net, I'm writing a time stamp to sql server, and wanted to keep the same format.

        dbUA->pzDateOpened = some sort of DateTime.Now();

        S Offline
        S Offline
        Satheesh1546
        wrote on last edited by
        #3

        Hi, You can use GetLocalTime().. SYSTEMTIME st; GetLocalTyme(&st); Thanks, Satheesh

        J 1 Reply Last reply
        0
        • S Satheesh1546

          Hi, You can use GetLocalTime().. SYSTEMTIME st; GetLocalTyme(&st); Thanks, Satheesh

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          Yeah I saw that, but it looks like I have to build up my Date Time with a structure or something. I didn't understand how to make the request. Perhaps I read it wrong, will look into again today. You included a sample, will give it a spin today. Thanks.

          1 Reply Last reply
          0
          • C Chandrasekharan P

            GetCurrentTime() function should work for you. [^]

            Every new day is another chance to change your life.

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            I didn't understand how to make the request, but I will look into again today.

            1 Reply Last reply
            0
            • J jkirkerx

              Is there an equivilent to the DateTime.Now() in asp.net, I'm writing a time stamp to sql server, and wanted to keep the same format.

              dbUA->pzDateOpened = some sort of DateTime.Now();

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              According to MSDN _ftime[^] is the equivalent.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              J 1 Reply Last reply
              0
              • L Lost User

                According to MSDN _ftime[^] is the equivalent.

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                J Offline
                J Offline
                jkirkerx
                wrote on last edited by
                #7

                Thanks for the help Richard. I was trying to inject the results into a datetime column in SQL via ODBC, but between the 2, it was hard to nail down the error. I didn't know if it was the format of the data, or ODBC not wanting to accept the LPSYSTEMTIME structure, or the size/precision of the data, which for some reason is 23,3. Ended up with this for now, it works, I can modify it later if I find something better.

                SYSTEMTIME systemTime;
                GetSystemTime(&systemTime);
                LPSYSTEMTIME lpSystemTime = &systemTime;

                swprintf_s(szDateOpened,
                L"%d-%d-%d %d:%d:%d",
                systemTime.wMonth,
                systemTime.wDay,
                systemTime.wYear,

                systemTime.wHour,
                systemTime.wMinute,
                systemTime.wSecond
                		);
                

                szDateOpened[wcslen(szDateOpened)] = L'\0';

                And then sent it to the ODBC Driver in another function. I just need to figure how how to create a MD5 Hash in UT8 for the Encoded Password, and then this part of the program is done.

                L"INSERT INTO UserInfo(FirstName, LastName, UserName, PhraseHint, Phrase, PasswordClear, DateOpened, Email, FrontAdmin, SecurityLevel, Enabled, LastLogin) "
                L"VALUES(?, ?, ?, ?, ?, ?, CAST(? as datetime), ?, ?, ?, ?, CAST(? AS datetime) )"

                and parameterized the values, that one liner took all day long.

                retcode = SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_VARCHAR, 23, 3, pzLastLogin, wcslen(pzLastLogin), NULL);

                L 1 Reply Last reply
                0
                • J jkirkerx

                  Thanks for the help Richard. I was trying to inject the results into a datetime column in SQL via ODBC, but between the 2, it was hard to nail down the error. I didn't know if it was the format of the data, or ODBC not wanting to accept the LPSYSTEMTIME structure, or the size/precision of the data, which for some reason is 23,3. Ended up with this for now, it works, I can modify it later if I find something better.

                  SYSTEMTIME systemTime;
                  GetSystemTime(&systemTime);
                  LPSYSTEMTIME lpSystemTime = &systemTime;

                  swprintf_s(szDateOpened,
                  L"%d-%d-%d %d:%d:%d",
                  systemTime.wMonth,
                  systemTime.wDay,
                  systemTime.wYear,

                  systemTime.wHour,
                  systemTime.wMinute,
                  systemTime.wSecond
                  		);
                  

                  szDateOpened[wcslen(szDateOpened)] = L'\0';

                  And then sent it to the ODBC Driver in another function. I just need to figure how how to create a MD5 Hash in UT8 for the Encoded Password, and then this part of the program is done.

                  L"INSERT INTO UserInfo(FirstName, LastName, UserName, PhraseHint, Phrase, PasswordClear, DateOpened, Email, FrontAdmin, SecurityLevel, Enabled, LastLogin) "
                  L"VALUES(?, ?, ?, ?, ?, ?, CAST(? as datetime), ?, ?, ?, ?, CAST(? AS datetime) )"

                  and parameterized the values, that one liner took all day long.

                  retcode = SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_VARCHAR, 23, 3, pzLastLogin, wcslen(pzLastLogin), NULL);

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I'm afraid my SQL skills are non-existent, but I would suggest you do not store dates and/or times as text values in a database but as datetime (i.e. binary) values. The remarks section in the documentation[^] suggest how to convert it to a large integer. This seems like a lot of work just to save a simple value, but it is Microsoft.

                  Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                  J 1 Reply Last reply
                  0
                  • J jkirkerx

                    Is there an equivilent to the DateTime.Now() in asp.net, I'm writing a time stamp to sql server, and wanted to keep the same format.

                    dbUA->pzDateOpened = some sort of DateTime.Now();

                    S Offline
                    S Offline
                    Satheesh1546
                    wrote on last edited by
                    #9

                    Hi, SYSTEMTIME st; GetLocalTime(&st); CString strHour, strMinute, strSecond; strHour.Format(_T("%d"), st.wHour); strMinute.Format(_T("%d"), st.wMinute); strSecond.Format(_T("%d"), st.wSecond); You can use this to get the current time. I f you need to update the time automatically.Use a timer with one second elapse time, and use this code in OnTimer(). Thanks

                    1 Reply Last reply
                    0
                    • L Lost User

                      I'm afraid my SQL skills are non-existent, but I would suggest you do not store dates and/or times as text values in a database but as datetime (i.e. binary) values. The remarks section in the documentation[^] suggest how to convert it to a large integer. This seems like a lot of work just to save a simple value, but it is Microsoft.

                      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                      J Offline
                      J Offline
                      jkirkerx
                      wrote on last edited by
                      #10

                      I casted it as datetime, in the ? mark, so sql server does the conversion. CAST(? as datetime) I'm starting to find out that SQL Server is not that popular in c++. must be a asp.net thing. Oh well. That was easy compared to hashing the password.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups