Hi,
I'm having a hard time trying to get a datetime value from my gridview to string in the correct format that I have set to display on the gridview.
I want: yyyy/MM/dd HH:ss ex. 2020/01/30 14:15
But the result keeps giving me 1/23/2020 2:05:08 PM
Then to string with all the non-alphanumeric removed it gives me: 1232020258PM (noticed it removed any 0s in front of the mins and secs...
I have already formatted the datetime on the gridview to display the correct format. But the value to string still gives me the other format.
I've also tried to grab the data from Sql database instead of gridview, however I still get the same result.
Ultimately, I need the correct format in the string so that I can eventually take it apart again to put in a different table. And why it will be in string is because i need to grab this info to include in the name of the PDF file. Then I'll make a table using info from the name breakdown to pull the PDF to put info a table to select it.
Help? Thank you!!!
My code:
private
void
radGridView1_CommandCellClick(
object
sender, GridViewCellEventArgs e)
{
plantCode = radGridView1.CurrentRow.Cells[
"plantCode"
].Value.ToString();
machine = radGridView1.CurrentRow.Cells[
"machine"
].Value.ToString();
ordNum = radGridView1.CurrentRow.Cells[
"productionOrderNum"
].Value.ToString().Substring(0, 7);
ordItem = radGridView1.CurrentRow.Cells[
"productionOrderNum"
].Value.ToString().Substring(8, 3);
apprStatus = radGridView1.CurrentRow.Cells[
"approvalList"
].Value.ToString();
custName = radGridView1.CurrentRow.Cells[
"addrName"
].Value.ToString();
process = radGridView1.CurrentRow.Cells[
"process"
].Value.ToString();
prodCode = radGridView1.CurrentRow.Cells[
"prodCode"
].Value.ToString();
custId = radGridView1.CurrentRow.Cells[
"custId"
].Value.ToString();
approvalTime = Regex.Replace(radGridView1.CurrentRow.Cells[
"approvalTime"
].Value.ToString(),
"[^a-zA-Z0-9]"
,
""
);
See I already formatted it on the datetime column in the gridview and this works fine displaying in the gridview:
gridViewTextBoxColumn16.DataType =
typeof
(System.DateTime);
gridViewTextBoxColumn16.FieldName =
"approvalTime"
;
gridViewTextBoxColumn16.FormatString =
"{0:yyyy/MM/dd HH:mm}"
;
gridViewTextBoxColumn16.HeaderText =
"approvalTime"
;
gridViewTextBoxColumn16.IsVisible =
false
;
gridViewTextBoxColumn16.Name =
"approvalTime"
;
gridViewTextBoxColumn16.ReadOnly =
true
;