-2

I would like for:

1) Submission Date label : To be a fixed date which is when the user submits the form (Created Date)

2) I need to calculate the number of days from when the user submits the form till the time the form is accessed by the server (Calculate the aging days) (Current Date)

My main issue is with trying to store the date the form is submitted on. Any ideas on how I can do this?

At the end of the day I need to display the submission day and aging days.

(Ps: I tried searching online but I can't seem to find anything to help me with this main issue. I'm also a newbie so I'll really appreciate if you were detailed in your explanation.)

Detailed Explanation:

If the user submits the form on 10 July 2015, the date submitted label would display 10/7/15. However, given that the person on the server side only attends to it today, 15 July 2015, the aging days would thus be the number of days between the 2 dates which would be 5.

I am able to get the current day (which would represent the date the person on the server side attends to the form. My issue is I need to store the date the form was submitted which would be 10 July 2015.

I have tried the code below to get the date the form was edited by the person on the server side:

DateLabel.Text = DateTime.Now.ToShortDateString();

Now, I need to be able to store the date the form was submitted to the server.

Both the submitted date and current day are represented in labels.

Thank you in advance!

Lucy MLJ
  • 59
  • 1
  • 11
  • Where are you storing the other data from the form? – phoog Jul 15 '15 at 04:15
  • Is this a web or winform application?? Also, which DBMS are you using?? – User2012384 Jul 15 '15 at 04:16
  • 2
    Have you tried anything ? This is rather simple. Also this is not a please code this for me site. – deathismyfriend Jul 15 '15 at 04:21
  • Can you post your codes here, so we can find what is lacking and wrong in your codes. You need to try on your own – dada Jul 15 '15 at 05:27
  • When getting the date back, the only issue I see is the formatting of the same due to different Globalization values set at client level. Is that the issue here? Pls. elaborate. – hiFI Jul 15 '15 at 05:42
  • @phoog For both the date the form was submitted and the aging days ( current day - submitted date) I will be storing them in labels. – Lucy MLJ Jul 15 '15 at 06:07
  • @User2012384 Webform. I'm connecting to access database. – Lucy MLJ Jul 15 '15 at 06:45
  • @LucyMLJ Then I'm a bit confused also, "form submission date" is the current date, there's no difference – User2012384 Jul 15 '15 at 06:50
  • @User2012384 For this, I have 2 users accessing the same form. Here, the buyer will submit the form and then the date the form submitted will be recorded. Once the form has been submitted, the 2nd user, logistic department, will review the form. Suppose the logistic department does not review the form on the day the form was submitted, the aging day will increase. This aging day is the difference in days between the submitted date and the date the form was accessed by the logistics department. – Lucy MLJ Jul 15 '15 at 07:22
  • Do you mean the date difference between created date and current date?? – User2012384 Jul 15 '15 at 07:23
  • @User2012384 Hence I need to store 2 dates. Firstly,the date the form was submitted by User 1. Then, the date the form was reviewed on by User 2. – Lucy MLJ Jul 15 '15 at 07:32
  • Yes exactly.Any idea on how I can get the created date? @User2012384 – Lucy MLJ Jul 15 '15 at 07:32
  • 1
    @LucyMLJ Did you SAVE the created date in the database? – User2012384 Jul 15 '15 at 07:36
  • 1
    A label is not a storage device. The date needs to be stored on the disk; this is usually done with a database. If the date is in the label, then it US in the computer's RAM, and will be lost when the computer is turned off. – phoog Jul 15 '15 at 13:51

2 Answers2

0

Like other said, your question is not clear to me also.

But let here are some things you can try:

SubmissionDatelabel.Text = DateTime.Now.ToString();
string Yesterday = DateTime.Today.AddDays(-1).ToString();  //-1 day
string Tomorrow = DateTime.Today.AddDays(1).ToString();    //+1 day

here are some basic tutorials about DateTime in C#

http://www.dotnetperls.com/datetime

http://www.c-sharpcorner.com/uploadfile/mahesh/working-with-datetime-using-C-Sharp/

http://www.csharp-examples.net/string-format-datetime/

http://www.homeandlearn.co.uk/csharp/csharp_s14p1.html

http://www.dotnetperls.com/datetime-elapsed

Calculate difference between two dates (number of days)?

Community
  • 1
  • 1
Dot_NET Pro
  • 2,095
  • 2
  • 21
  • 38
0
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Empty
{
    public partial class WebForm5 : System.Web.UI.Page
    {

        string sk = @"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=storingdata;Integrated Security=True";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["mob_id"].ToString() == "" || Session["mob_id"] == null)
            {
                Response.Write("<script>alert('Session Expired Login Again');</script>");
                //Response.Redirect("login.aspx");
            }
            else
            {

                if (!Page.IsPostBack)
                {
                    getUserprojectData();



                }


            }



        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            /// Verifies that the control is rendered /
        }
        private void bingridview()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("mob_id", typeof(string));
            dt.Columns.Add("Projects", typeof(string));
            dt.Columns.Add("FromDtae", typeof(string));
            dt.Columns.Add("ToDate", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("Hours", typeof(string));
            GridView2.DataSource = dt;
            GridView2.DataBind();



        }
        void getUserprojectData()
        {
            SqlConnection con = new SqlConnection(sk);
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            //  SqlCommand cmd = new SqlCommand("select * from login_tbl where mob_id='" + TextBox1.Text.Trim() + "' AND password='" + TextBox2.Text.Trim() + "'", con);
            SqlCommand cmd = new SqlCommand("SELECT mob_id, Projects FROM ProjectList WHERE mob_id='" + Session["mob_id"].ToString() + "';", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            GridView2.DataSource = dt;
            GridView2.DataBind();
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("mob_id", typeof(string));
            dt.Columns.Add("Projects", typeof(string));
            dt.Columns.Add("FromDtae", typeof(string));
            dt.Columns.Add("ToDate", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("Hours", typeof(string));
            foreach (GridViewRow row in GridView2.Rows)
            {
                Label b1 = (Label)row.Cells[0].FindControl("Label1");
                Label b2 = (Label)row.Cells[1].FindControl("Label2");
                //TextBox b3 = (TextBox)row.Cells[2].FindControl("TextBox1");
                //TextBox b4 = (TextBox)row.Cells[3].FindControl("TextBox2");
                TextBox b5 = (TextBox)row.Cells[4].FindControl("TextBox3");
                TextBox b6 = (TextBox)row.Cells[5].FindControl("TextBox4");
                DataRow dr = dt.NewRow();
                dr["mob_id"] = ((Label)row.FindControl("Label1")).Text;
                dr["Projects"] = ((Label)row.FindControl("Label2")).Text;
                //dr["FromDtae"] = ((TextBox)row.FindControl("TextBox1")).Text;
                //dr["ToDate"] = ((TextBox)row.FindControl("TextBox2")).Text;
                dr["Description"] = ((TextBox)row.FindControl("TextBox3")).Text;
                dr["Hours"] = ((TextBox)row.FindControl("TextBox4")).Text;
                dt.Rows.Add(dr);


                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sk"].ConnectionString);
                SqlCommand cmd = new SqlCommand("INSERT INTO hour_tbl(mob_id, Projects,Description, Hours) values" +
                       "('" + b1.Text + "','" + b2.Text + "','" + b5.Text + "','" + b6.Text + "')", con);

                con.Open();
                cmd.ExecuteReader();
                con.Close();
            }
        }


    
    }
}


in this i used to save the gridview to database for a particular user butthe values are empty while checking using breakpoint in database also it stores empty