DatetimePickerde seçilen tarihin bir gün öncesi,bir hafta öncesi,bir ay öncesi,bir yıl sonrası — Csharp
DatetimePickerde seçilen tarihin bir gün öncesi,bir hafta öncesi,bir ay öncesi,bir yıl sonrası — Csharp
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; //www.gorselprogramlama.com/ using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DateTime tarih =Convert.ToDateTime( dateTimePicker1.Text); DateTime BirGunOncesi = tarih.AddDays(-1); DateTime BirHaftaOncesi = tarih.AddDays(-7); //www.gorselprogramlama.com/ DateTime BirAyOncesi = tarih.AddMonths(-1); DateTime BirYilSonrasi = tarih.AddYears(1); label5.Text = BirGunOncesi.ToString(); label6.Text = BirHaftaOncesi.ToString(); label7.Text = BirAyOncesi.ToString(); label8.Text = BirYilSonrasi.ToString(); } } }
Not : Yukarıdaki saat kısımlarının yan, 00:00:00 kısmının gözükmesini istemiyorsanız ekrana yazdırırken ToString() yerine ToShortDateString() kullanılmalı.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; //www.gorselprogramlama.com/ using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DateTime tarih =Convert.ToDateTime( dateTimePicker1.Text); DateTime BirGunOncesi = tarih.AddDays(-1); DateTime BirHaftaOncesi = tarih.AddDays(-7); //www.gorselprogramlama.com/ DateTime BirAyOncesi = tarih.AddMonths(-1); DateTime BirYilSonrasi = tarih.AddYears(1); label5.Text = BirGunOncesi.ToShortDateString(); label6.Text = BirHaftaOncesi.ToShortDateString(); label7.Text = BirAyOncesi.ToShortDateString(); label8.Text = BirYilSonrasi.ToShortDateString(); } } }