You must Sign In to post a response.
  • Category: Visual Studio

    Data type and procedures

    Hi, Every one
    I have questions
    0. I have many text boxes to Enter the values and than saved to database , here specially what type of properties I should use for DTP.
    1. What data type I should use for date field in the name mydate.
    2. In the DTP what properties I should use to store the date like this , 29-11-2016.
    3. How and what properties I should use to display the same date in listview area in the row for all the table records, and the date in the same format and pattern.
    4. when I click on any row all the values should go back to its related text boxes including the DTP text box in the same format of data type and format I mention above.

    Please I want informations before I start writting the code , because date is little bit confusing me. Thanks
  • #768411
    Hi,

    For your first question, If you have so many parameters that you are passing to the database which also contain Date field as majority, you can go for Varchar Datatype. The biggest advantage of using that is we can easily convert into any datatype without loss of any data.

    Now coming to the date conversation, This is easiest way to convert date into any format as we like,
    Suppose you have variable like,


    var dt = "11/30/2016 12:00:00:000"


    and you like to convert on your desire format.


    String.Format("{0:dd-MM-yyyy}", dt);


    Result will be "30-11-2016"
    Some more examples,


    DateTime _date;
    string day = "";

    _date = DateTime.Parse("11/20/2016");
    day = _date.ToString("dd-MMM-yyyy");


    Output : It will output as: 20-Nov-2016

    For any date format conversion check the below website:
    http://www.csharp-examples.net/string-format-datetime/

    Thanks,
    Mani

  • #768426
    You can use DateTime to store the date. Example
    using System;

    class Program
    {
    static void Main()
    {
    DateTime value = new DateTime(2016, 11, 30);
    Console.WriteLine(value);
    Console.WriteLine(value == DateTime.Today);
    }
    }

    Output : 30/11/2016 05:00:00 AM
    True

  • #768450
    Hi,

    The question which you asked all are basics, before answering to your question I have a question to you have you Google the same question?

    I think you didn't if you did that you never come back with same question.

    If you want to show only date in your control then you can convert like below

    DateTime.Now.ToString("dd-MM-yyyy");


    If you want to convert string to DateTime then you can use

    Convert.ToDateTime();
    DateTime.Parse();
    DateTime.ParseExact();
    DateTime.TryParse();

    first understood all the basics then only move forward, other wise no use...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments