CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181

    how do I get "9/30/2002 12:00:01 PM"

    How do I get today's date to be: "9/30/2002 12:00:01 PM"?



    // added 09.30.2002
    CString sDateTimeToday;
    sDateTimeToday = Today.Format(_T("%A, %B %d, %Y"));

    sDateTimeToday = Today.Format(VAR_DATEVALUEONLY);

    COleDateTime sDateTimeTodayCOle = COleDateTime::GetCurrentTime();

    CString s = sDateTimeTodayCOle.Format(_T("%Y-%M-%D 00:00:00.000"));


    Wango

  2. #2
    Join Date
    Sep 2002
    Posts
    36
    Try this


    CString strToday;
    COleDateTime today = COleDateTime::GetCurrentTime();

    if (today.GetHour() > 12)
    {
    strToday.Format("%d/%02d/%4d %02d:%02d:%02d PM",
    today.GetMonth(),
    today.GetDay(),
    today.GetYear(),
    today.GetHour() - 12,
    today.GetMinute(),
    today.GetSecond());
    }
    else
    {
    strToday.Format("%d/%2d/%4d %2d:%2d:%2d AM",
    today.GetMonth(),
    today.GetDay(),
    today.GetYear(),
    today.GetHour(),
    today.GetMinute(),
    today.GetSecond());
    }


    Regards

    Rolf

  3. #3
    Join Date
    Sep 2002
    Posts
    36
    Oups sorry, some copy/paste problem, lol

    in the else you should also have the same format string as below

    strToday.Format("%d/%02d/%4d %02d:%02d:%02d PM",

  4. #4
    Join Date
    Sep 2002
    Posts
    36
    Except with AM and not PM (poor tired Rolf )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured