Thread: How to pass values to a dateTimePicker control

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    How to pass values to a dateTimePicker control

    Hello everyone,
    i have a String^ in the format of DD/MM/YYYY and i wanna pass that value to set the date of a dateTimePicker control.
    i know the code is
    Code:
    dateTimePicker1->Value = DateTime(YEAR, MONTH, DAY);
    but my problem is splitting the date String^ into 3 seperate strings(YEAR, MONTH, DAY).

    I need help on how to do this. Mind you, sometimes the string format is
    D/MM/YYYY (like today 4/11/2007) and other times
    DD/MM/YYYY (eg 25/10/2007).
    Same applies to the month,
    DD/M/YYYY(10/1/2007) and
    DD/MM/YYYY(10/12/2007).

    Thank You.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Code:
    #include <stdio.h>
    
    void SeparateStrings(char *inputDate, char *outDay, char *outMonth, char *outYear)
    {
        int i = 0;
        int j = 0;
        int k = 0;
        int flag = 0;
    
        while (inputDate[i] != '\0')
        {
            if (flag == 0)
            {
                if (inputDate[i] == '/')
                {
                    flag = 1;
                    outDay[i] = '\0';
                } 
                else outDay[i] = inputDate[i];
            }
            else if(flag == 1)
            {
                if (inputDate[i] == '/')
                {
                    flag = 2;
                    outMonth[j] = '\0';
                }
                else outMonth[j++] = inputDate[i];
            }
            else outYear[k++] = inputDate[i];
            i++;
        }
    }
    
    int main(void)
    {
        char szDay[128] = {0};
        char szMonth[128] = {0};
        char szYear[128] = {0};
        SeparateStrings("4/11/2007", szDay, szMonth, szYear);
        printf("%s   %s   %s\n", szDay, szMonth, szYear);
        SeparateStrings("25/10/2007", szDay, szMonth, szYear);
        printf("%s   %s   %s\n", szDay, szMonth, szYear);
        SeparateStrings("10/1/2007", szDay, szMonth, szYear);
        printf("%s   %s   %s\n", szDay, szMonth, szYear);
        SeparateStrings("10/12/2007", szDay, szMonth, szYear);
        printf("%s   %s   %s\n", szDay, szMonth, szYear);
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. Help passing and storing
    By devilsknight in forum C Programming
    Replies: 7
    Last Post: 07-03-2006, 03:20 AM
  3. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  4. datetimepicker in C# .net
    By Micko in forum C# Programming
    Replies: 0
    Last Post: 05-30-2004, 11:58 AM
  5. Edit Control problem
    By Malek in forum Windows Programming
    Replies: 3
    Last Post: 06-16-2002, 01:12 AM