5 Replies - 3524 Views - Last Post: 24 May 2010 - 02:18 AM Rate Topic: -----

#1 jellybeannn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 15-February 10

Date day and month swap

Posted 24 May 2010 - 01:00 AM

Hi, I've got a input sheet where start and end dates are saved to a access database, I do have the access database dates field as Date/Time with a short date format. On my output page the start date's month and day are swapped but only if the actual day is between(1-12) else its fine. I've checked the database it does save the date as yyyy/mm/dd. But I've got the same code for start and end date, but only startDate has this problem.

I don't where this error may occure and I do have so much code, so could someone please give me some advice.

Oh this only happens on the server, not on the localhost.

This post has been edited by jellybeannn: 24 May 2010 - 01:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Date day and month swap

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Date day and month swap

Posted 24 May 2010 - 01:21 AM

Could you post some of your code... I believe there must be something wrong with your code...
Was This Post Helpful? 0
  • +
  • -

#3 Mion  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 23-April 10

Re: Date day and month swap

Posted 24 May 2010 - 01:37 AM

It'll have something to do with the regional settings on the server then but you probably don't want ant to mess with that in-case you muck up something else so......

A quick google turned up this : -

DateTime thisDate = new DateTime(2008, 3, 15);
CultureInfo culture = new CultureInfo("pt-BR");      
Console.WriteLine(thisDate.ToString("d", culture));  // Displays 15/3/2008



In fact that was in the very first link... have you tried this? I've got to admit I'm wondering if you even tried searching...
Was This Post Helpful? 0
  • +
  • -

#4 jellybeannn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 15-February 10

Re: Date day and month swap

Posted 24 May 2010 - 01:38 AM

This is where the data is added to the access database in input.aspx.cs, for the dates a javascript date picker is used.
public void addData()
    {
        string name = name_txt.Text;
        string currency = currency_txt.Text;
        string cost = cost_txt.Text;
        string start = testinput.Text;
        string completion = testinput2.Text;
        string locality = locality_dd.SelectedItem.Text;
        string sector = sector_dd.SelectedItem.Text;
        string superstructure = superstructure_dd.SelectedItem.Text;
        string lifts = lifts_dd.SelectedItem.Text;
        string excavation = excavation_dd.SelectedItem.Text;
        int validation = Int32.Parse(validation_txt.Text);
        string holiday_str = holiday_txt.Text;
        int holiday = 0;
        if (holiday_str == "Yes")
        {
            holiday = 1;
        }
        else
        {
            holiday = 0;
        }
        string alpha_beta = locality_dd.SelectedValue.ToString() + sector_dd.SelectedValue.ToString() +
            superstructure_dd.SelectedValue.ToString() + lifts_dd.SelectedValue.ToString() +
            excavation_dd.SelectedValue.ToString();
        int code = Int32.Parse(alpha_beta);

        //string scon =
        //    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\www\\solarsearch.co.za\\wwwroot\\calc\\app_data\\calculator.mdb";
        string scon =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|calculator.mdb";
        string str =
           "INSERT INTO form_input(identification, symbol, cost, start, completion, locality, sector, superstructure, lifts, excavation, validation, holiday, code)values(name, currency, cost, start, completion, locality, sector, superstructure, lifts, excavation, validation, holiday, code)";
        string id = "Select @@Identity";
        int f_id;
        using (OleDbConnection con = new OleDbConnection(scon))
        {
            using (OleDbCommand cmd = new OleDbCommand(str, con))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("identification", name);
                cmd.Parameters.AddWithValue("symbol", currency);
                cmd.Parameters.AddWithValue("cost", cost);
                cmd.Parameters.AddWithValue("start", start);
                cmd.Parameters.AddWithValue("completion", completion);
                cmd.Parameters.AddWithValue("locality", locality);
                cmd.Parameters.AddWithValue("sector", sector);
                cmd.Parameters.AddWithValue("superstructure", superstructure);
                cmd.Parameters.AddWithValue("lifts", lifts);
                cmd.Parameters.AddWithValue("excavation", excavation);
                cmd.Parameters.AddWithValue("validation", validation);
                cmd.Parameters.AddWithValue("holiday", holiday);
                cmd.Parameters.AddWithValue("code", code);
                con.Open();
                cmd.ExecuteNonQuery();
                cmd.CommandText = id;
                f_id = (int)cmd.ExecuteScalar();

                message.Text = "Submission was Successful";
                Response.Redirect("output.aspx?f_id=" + f_id);
            }
        } 
    }



This is where the data is read from the database output.aspx.cs
public DataSet GetTable()
    {
        string f_id = Request.QueryString["f_id"];

        //string strConnString =
        //  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\www\\solarsearch.co.za\\wwwroot\\calc\\app_data\\calculator.mdb";
        string strConnString =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|calculator.mdb";

        OleDbConnection con = new OleDbConnection(strConnString);
        con.Open();

            // read from form_input table
        string strQuery = "select * from form_input where f_id=" + f_id;
        OleDbCommand cmd = new OleDbCommand(strQuery, con);
        OleDbDataReader reader = cmd.ExecuteReader();
        reader.Read();

        string company = reader["identification"].ToString();
        string start_str = reader["start"].ToString();
        DateTime start = DateTime.Parse(start_str);
        string end_str = reader["completion"].ToString();
        DateTime end = DateTime.Parse(end_str);
        string cost = reader["cost"].ToString();
        double b = double.Parse(cost);
        string validDay_str = reader["validation"].ToString();
        int validDay = Int32.Parse(validDay_str);
        string code = reader["code"].ToString();
        string holiday_str = reader["holiday"].ToString();
        int holiday = Int32.Parse(holiday_str);
        string symbol = reader["symbol"].ToString();
        string locality_str = reader["locality"].ToString();
        string sector_str = reader["sector"].ToString();
        string super_str = reader["superstructure"].ToString();
        string lifts_str = reader["lifts"].ToString();
        string excavation_str = reader["excavation"].ToString();

            // read from alpha_beta table
        string strQuery2 = "select * from alpha_beta where code=" + code;
        OleDbCommand cmd2 = new OleDbCommand(strQuery2, con);
        OleDbDataReader reader2 = cmd2.ExecuteReader();
        reader2.Read();
        string construction_a_str = reader2["construction_a"].ToString();
        string construction_b_str = reader2["construction_b"].ToString();
        string top_a_str = reader2["top_a"].ToString();
        string top_b_str = reader2["top_b"].ToString();
        string bottom_a_str = reader2["bottom_a"].ToString();
        string bottom_b_str = reader2["bottom_b"].ToString();

            // alpha_beta values
        double construction_a = double.Parse(construction_a_str);
        double construction_b = double.Parse(construction_b_str);
        double top_a = double.Parse(top_a_str);
        double top_b = double.Parse(top_b_str);
        double bottom_a = double.Parse(bottom_a_str);
        double bottom_b = double.Parse(bottom_b_str);

            // display labels
        companyName.Text = company;
        todayDate.Text = (String.Format("{0:yyyy/MM/dd}", DateTime.Now));
        currency.Text = symbol;
        constructionCost.Text = cost;
        startDate.Text = (String.Format("{0:dd MMMM yyyy}", start)); //here values are swapped as well as with the valuation dates later on
        endDate.Text = (String.Format("{0:dd MMMM yyyy}", end));
        valuationDay.Text = validDay_str;
        locality.Text = locality_str;
        sector.Text = sector_str;
        super.Text = super_str;
        lifts.Text = lifts_str;
        mass.Text = excavation_str;

        if (holiday == 1)
            apply.Text = "Yes";
        else
            apply.Text = "No";

            // display
        DataSet ds = new DataSet();
        DataTable dt = ds.Tables.Add("Table");
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(string)));
        dt.Columns.Add(new DataColumn("Upper Probability Limit", typeof(string)));
        dt.Columns.Add(new DataColumn("Lower Probability Limit", typeof(string)));

            // fill rows
        foreach (DateTime valuationDate in GetDates(start, end, validDay))
        {
            int numberOfDays = 0;
            if (valuationDate.Month == 12 || valuationDate.Month == 01)
            {
                numberOfDays = 14;
            }
            current += numberOfDays;

            DataRow row = dt.NewRow();
            row["Valuation Date"] = valuationDate.ToString("yyyy/MM/dd");
            row["Construction Cash Flow"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, construction_a, construction_B)/>;
            row["Upper Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, top_a, top_B)/>;
            row["Lower Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, bottom_a, bottom_B)/>;
            dt.Rows.Add(row);
        }

        reader2.Close();
        reader.Close();
        con.Close();
        return ds;
    }


Was This Post Helpful? 0
  • +
  • -

#5 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Date day and month swap

Posted 24 May 2010 - 02:07 AM

Since this is a web application, you should post this question in ASP.NET section on this forum.

If you retrieve your date as a string, then I suggest you parse the date to a DateTime object like so:

string date = "31/12/2010";
DateTime dateTime = DateTime.Parse(date);


Was This Post Helpful? 0
  • +
  • -

#6 jellybeannn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 15-February 10

Re: Date day and month swap

Posted 24 May 2010 - 02:18 AM

It seems to be the regional settings, I'm trying to set this in the web.config, but it does not change anyhting.

<globalization culture="en-ZA" uiCulture="en-ZA"/>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1