473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to compare system date with database date?

how to compare a current system date with a database entry(date) pls explain in code,to be used in the indicator.
Sep 22 '11 #1
2 826
Frinavale
9,735 Expert Mod 8TB
Well first you need to retrieve the date from the database. If you don't know how to do this then check out the article about How to use a database in your program.


When you do this be sure to use the DateTime Parsing Methods to convert the date retrieved into something that you can use to compare to the systems DateTime.

Then use the DateTime.Now property to retrieve the system's date....

-Frinny
Sep 23 '11 #2
adriancs
122 100+
Here is any example of comparing Database of MySQL with C# datetime:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using MySql.Data.MySqlClient;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             string conn = "server=localhost;user=root;password=qwerty;database=customer;";
  22.             MySqlConnection myconn = new MySqlConnection(conn);
  23.             string sql = "SELECT `date` FROM `member` WHERE `memberid` = '1';";
  24.             MySqlDataAdapter da = new MySqlDataAdapter(sql, myconn);
  25.             DataTable dt = new DataTable();
  26.             da.Fill(dt);
  27.  
  28.             if (dt.Rows.Count == 0)
  29.             {
  30.                 MessageBox.Show("No data found.", "No Data");
  31.             }
  32.             else
  33.             {
  34.                 try
  35.                 {
  36.                     DateTime dtimeNow = DateTime.Now;
  37.                     DateTime dtimeDB = Convert.ToDateTime(dt.Rows[0][0]);
  38.  
  39.                     if (dtimeDB == dtimeNow)
  40.                     {
  41.                         // Do something...
  42.                     }
  43.                     else if (dtimeDB > dtimeNow)
  44.                     {
  45.                         // Do something...
  46.                     }
  47.                     else if (dtimeDB < dtimeNow)
  48.                     {
  49.                         // Do something...
  50.                     }
  51.                     else
  52.                     { }
  53.                 }
  54.                 catch (Exception ex) // Capture any error occur
  55.                 {
  56.                     MessageBox.Show(ex.ToString());
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Oct 4 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Piotr Pietrowski | last post by:
Hello everybody, I have a *big* problem. I thought its not that big problem for you professionals... Anyway, I have a begin date which has 3 dropdown boxes (day/Month/Year). The same for the...
7
by: joeyej | last post by:
How do I compare today's date with this string (in my inc file) so that I can set an alert if date choice i.e. May 15, 2006 not at least greater than two days from current date? <option...
2
by: Drum2001 | last post by:
Hello, I am having isues with the following: I have two forms, a MAIN FORM with a SUB FORM: Within the MAIN FORM, I have an unbound textbox (Date Format) and a command button. Onload, the...
0
sashi
by: sashi | last post by:
Format database date. This snippet of code will allow you to take in a date parameter. It will check the date parameter to see if there is a valid time portion or not. It will then format the...
12
vdraceil
by: vdraceil | last post by:
Hi experts, I have a question. Is it possible to set (change/edit) the system time and date by coding in vb6.0? I think it's not possible (80%) but maybe experts might have an answer - I suppose.
3
by: lyndac | last post by:
Hello! Last night a job to create a view using DATE(CURRENT DATE - 1 DAY) received the current days date instead the previous days date. Any one know why/how this can happen? The...
4
by: ghjk | last post by:
I want to compare user entered date with data base datetime value. Database value in datetime type and first i want to extract date part and then compare with user entered value. This is my query....
1
by: ShwetaJain | last post by:
Hi... I am able to get the type of the message as IPM.Appointmnet in the inbox but i am unable to get the due date, start date, for that appointment.... I am using MAPI in exchange server but i...
1
by: smdmca | last post by:
I have Julian date, I want to convert it into date. Is there any function in MySql to convert Julian date to date eg- Julian Date- 2455116 Date - Oct - 12, 2009
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.