• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

C# WinForms APP -- DateTime.Now via SERVER ?

How can I change the below Windows Forms APP code
to something like "servername.DateTime.Now" ?

It currently uses the LOCAL PC's
clock which is not always correct.
        private void btn_StopComplete_Click(object sender, EventArgs e)
            dateTimeDateTimePicker.Value = DateTime.Now;
            string beforeHour = DateTime.Now.Hour.ToString();
            string beforeMinute = DateTime.Now.Minute.ToString();

            IFS_MiscDataSet.Time_ScanningDataTable dtRecords = new IFS_MiscDataSet.Time_ScanningDataTable();
            dtRecords = time_ScanningTableAdapter.getOneEmpIDOSID_DT(Convert.ToInt32(sEmpNo));
            foreach (DataRow drRec in dtRecords.Rows)
                DateTime a = Convert.ToDateTime(drRec["DateTime"].ToString());
                TimeSpan b = DateTime.Now.Subtract(a);
3 Solutions
Kyle AbrahamsSenior .Net DeveloperCommented:
From here:

You can use the NTPClientClass to make a call out to the internet to get the real time.
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:

You must be using some kind of database whether it be SQL Server or MySQL or other.
You can always query the database system to get the currect current time. i.e. GETDATE()

where it uses the command variable use

"net time \\yourservername";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now