Hey guys, I'm using this code:
string date = eventStartDate.Text;
string hour = eventStartHour.Text;
string min = eventStartMinute.Text;
string dateString = date + " " + hour + ":" + min;
string[] format = new string[] { "d/M/yyyy h:mm", "d/M/yyyy h:mm:ss", "d-M-yyyy h:mm", "dd-MM-yyyy hh:mm" };
DateTime dateTime;
DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime);
Console.WriteLine(dateTime);
and it's working but just not giving the format I want it to... I want something along the lines of:
"dd/MM/yyyy hh:mm" or "dd-MM-yyyy hh:mm" Which CultureInfo should I use for that?
I'm doing this to pass them to the DB:
protected void submit_Click(object sender, EventArgs e)
{
DateTime eventStart = dates(eventStartDate.Text, eventStartHour.Text, eventStartMinute.Text);
DateTime departure = dates(departureDate.Text, departureHour.Text, departureMinute.Text);
DateTime arrival = dates(arrivalDate.Text, arrivalHour.Text, arrivalMinute.Text);
Console.WriteLine(arrival);
DateTime flightDeparture = dates(flightDepartureStartDate.Text, flightDepartureStartHour.Text, flightDepartureStartMinute.Text);
DateTime flightReturn = dates(flightReturnStartDate.Text, flightReturnStartHour.Text, flightReturnStartMinute.Text);
byte[] file = (byte[])Session["File"];
string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
string ConStr = ConfigurationManager.ConnectionStrings["FORgestIT"].ToString();
SqlConnection SQLConn = new SqlConnection(ConStr);
SqlCommand SQLCmd = new SqlCommand();
SQLCmd.Connection = SQLConn;
SQLCmd.CommandType = CommandType.Text;
SQLCmd.CommandText = "INSERT INTO Event (Name, Project, Objectives, City, Country, Event_Start, Departure, Arrival, Registration, National_Transportation, Accomodation, AC_NumberNights, AC_PreferHotelURL, Flight, FL_departure, FL_Depart_Prefer, FL_Depart_URL, FL_Return, FL_Ret_Prefer, FL_RET_URL, Notes, File, Status) VALUES (@Name,@Project,@Objectives,@City,@Country,@Event_Start,@Departure,@Arrival,@Registration,@National_Transportation,@Accomodation,@AC_NumberNights,@AC_PreferHotel,@AC_PreferHotelURL,@Flight,@FL_Departure,@FL_Depart_Prefer,@FL_Depart_URL,@FL_Return,@FL_Ret_Prefer,@FL_Ret_URL,@Notes,@File,@Status)";
SQLCmd.Parameters.Clear();
SQLCmd.Parameters.AddWithValue("@Name", name.Text);
SQLCmd.Parameters.AddWithValue("@Project", project.Text);
SQLCmd.Parameters.AddWithValue("@Objectives", objectives.Text);
SQLCmd.Parameters.AddWithValue("@City", venueCity.Text);
SQLCmd.Parameters.AddWithValue("@Country", venueCountry.Text);
SQLCmd.Parameters.AddWithValue("@Event_Start", eventStart);
SQLCmd.Parameters.AddWithValue("@Departure", departure);
SQLCmd.Parameters.AddWithValue("@Arrival", arrival);
SQLCmd.Parameters.AddWithValue("@Registration", registrationInformation.Text);
SQLCmd.Parameters.AddWithValue("@National_Transportation", rdlYesNo.SelectedValue);
SQLCmd.Parameters.AddWithValue("@Accomodation", accomodation.SelectedValue);
SQLCmd.Parameters.AddWithValue("@AC_NumberNights", numberOfNights.Text);
SQLCmd.Parameters.AddWithValue("@AC_PreferHotel", preferredHotel.Text);
SQLCmd.Parameters.AddWithValue("@AC_PreferHotelURL", preferredHotelURL.Text);
SQLCmd.Parameters.AddWithValue("@Flight", flight.SelectedValue);
SQLCmd.Parameters.AddWithValue("@FL_Departure", flightDeparture);
SQLCmd.Parameters.AddWithValue("@FL_Depart_Prefer", flightDeparturePreferred.Text);
SQLCmd.Parameters.AddWithValue("@FL_Depart_URL", flightDeparturePreferredURL.Text);
SQLCmd.Parameters.AddWithValue("@FL_Return", flightReturn);
SQLCmd.Parameters.AddWithValue("@FL_Ret_Prefer", flightReturnPreferred.Text);
SQLCmd.Parameters.AddWithValue("@FL_Ret_URL", flightReturnPreferredURL.Text);
SQLCmd.Parameters.AddWithValue("@Notes", notes.Text);
SQLCmd.Parameters.AddWithValue("@File", file);
SQLCmd.Parameters.AddWithValue("@Status", "Pending");
if (SQLConn.State == ConnectionState.Closed)
{
SQLConn.Open();
}
SQLCmd.ExecuteNonQuery();
SQLConn.Close();
string url = "Default.aspx";
ClientScript.RegisterStartupScript(this.GetType(), "callfunction", "alert('Your request form was saved correctly!');window.location.href = '" + url + "';", true);
}