C# DateTimePicker => Set and Get Date

c# crud

So guys here we look at C# DateTimePicker.This is our first DateTimePicker lesson so its a simple one.The aim is to see how to retrieve date from a DateTimePicker and also how to set the date. We are setting date to datetimepicker from a textbox and also retrieve it and show it there. DateTimePickers allow us an easy way to work with dates in .NET. You can easily select the date and use without going to the hassle of remembering Date formats.We want to programmatically set and get the datetimepicker value.  

How To Download and Run

  • Download the project above.
  • You'll get a zipped file,extract it.
  • Open the Visual Studio.
  • From the Menu bar click on File >Open > Project/Solution
  • Now Choose a Destination Folder, from where you have the extracted project.
  • Now Click on “OK“.
  • Done, Now edit it.

 

Our Classes

Form 1 Class

  • This is our main class of course.
  • Add DateTimePicker to your Form and a textbox and two buttons : Get and Set.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DateTimePicker
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    //GET DATE
    private void getBtn_Click(object sender, EventArgs e)
    {
      txtValue.Text = dateTimePicker1.Value.ToShortDateString();
    }

    //SET DATE
    private void setBtn_Click(object sender, EventArgs e)
    {
      dateTimePicker1.Value = DateTime.Parse("10/10/2006");

    }
  }
}

 

More

YouTube

  • Visit our channel for more examples like these.

Facebook

Oclemy,Cheers.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post