So in my application I extract data from a database and then extract it to a csv file and I say what I want under each columns like so:
public List<ExtractDocument> GetExtractDocuments(List<Guid>ItemDetailIds)
{
var items = GetExtractData(ItemDetailIds);
return items.Select().Select(item => new ExtractDocument
{
ItemDetailId = item.Field<Guid>("ItemDetailID"),
ItemNumber = item.Field<string>("Number"),
ItemTitle = item.Field<string>("Title"),
ItemRevision = item.Field<string>("RevisionNumber"),
ActionType = item.Field<string>("Action"),
ActionedBy = item.Field<string>("ActionedBy"),
ActionedDate = item.Field<DateTime?>("ActionedDate")?.ToString("dd/MM/yyyy HH:mm:ss.fff"),
Comment = item.Field<string>("Comment"),
TaskType = item.Field<string>("TaskType"),
StartDate = item.Field<DateTime?>("StartDate")?.ToString("dd/MM/yyyy HH:mm:ss.fff"),
CompletedDate = item.Field<DateTime?>("CompletedDate")?.ToString("dd/MM/yyyy HH:mm:ss.fff"),
Status = item.Field<string>("Status"),
Outcome = item.Field<string>("Outcome"),
ActionerName = item.Field<string>("TaskActionedBy"),
DateActioned = item.Field<DateTime?>("ActionDate")?.ToString("dd/MM/yyyy HH:mm:ss.fff"),
ActionTaken = item.Field<string>("TaskAction"),
TaskComment = item.Field<string>("TaskComment"),
Link = item.Field<string>("URL")
}).ToList();
}
This is working but when I open up the csv file and look under the date columns such as "ActionedDate" the date is showing up in a weird way, for example one of the values should be showing as: 03/03/2022 09:07:46 but it is showing in the field as:07:46.3, why is it doing this and how I can prevent that from happening? it doesn't do this for all the fields but it does for the majority
Yeah this was a face palm moment, just realised I had the format written as: "dd/MM/yyyy HH:mm:ss.fff" when it should be "dd/MM/yyyy HH:mm:ss:fff", changing it from ss.fff to ss:fff, fixed the issue
Related
public JsonResult GetAll()
{
Entities contextObj = new Entities();
var employeeList = contextObj.CCFFares.ToList();
//return Json(employeeList, JsonRequestBehavior.AllowGet);
return this.Json((from obj in contextObj.CCFFares
select new
{
ID = obj.ID,
Departure_Airport = obj.Departure_Airport,
Destination = obj.Destination,
Departure_Date = obj.Departure_Date.ToString(),
Return_Date = obj.Return_Date.ToString(),
Airline = obj.Airline,
Fare = obj.Fare,
Offer_Ends = obj.Offer_Ends,
Ailine_Class = obj.Airline_Class
}), JsonRequestBehavior.AllowGet);
}
I got an issue where i need to show the date in dd/mm/yy but i am receiving in this manner 2/20/2017 12:00:00 AM what i really dint want to and when i bind the value in view without to string conversion i do get the date time in this way " /Date(1479600000000)/ "where i need to show the date in dd/mm/yy simply can someone guide me on this please !
While binding to your html view use date filter as follows
{{your date in milliseconds| date:'dd/MM/yyyy'}}
Keep .toString() as it is
Try by adding custom filter for date
Angular code
app.filter('filterDate', ['$filter', function ($filter) {
return function (input, format) {
return (input) ? $filter('date')(input, format) : '';
};
Your Html should be like
<li class="mark"> {{Departure_Date | filterDate : 'dd-MM-yy' }}</li>
I have a list in the form-
FieldName- DataType-
Date DateTime
DateString String
Unit double
Price double
I want to perform an operation such that if weakday on Date is not Monday then update DateString with empty string otherwise keep the value of DateString as it is.
Data is present in List.
UPDATE
I have applied aggregate function on DataTable dtGas as follows-
var qGas = from x in dtGas.AsEnumerable()
group x by new
{
Date = x.Field<DateTime>("Date"),
DateString = x.Field<string>("DateString")
} into egroup
select new
{
Date = egroup.Key.Date,
DateString = egroup.Key.DateString,
Unit = egroup.Sum(r => r.Field<double>("Unit")),
Price = egroup.Sum(r => r.Field<double>("Price"))
};
Now I need to show this result into Chart. Due to large amount of data values are overlapping on X-axis.
That is why I need to remove some values from DateString and show only few of them.
You can simply use conditional operator like this:-
group x by new
{
Date = x.Field<DateTime>("Date"),
DateString = x.Field<string>("DateString")
} into egroup
let isMonday = egroup.Key.Date.DayOfWeek.ToString() == "Monday"
select new
{
Date = egroup.Key.Date,
DateString = isMonday ? egroup.Key.DateString : "",
..other properties
I have datetime column in gridview:
settings.Columns.Add(clmn =>
{
clmn.FieldName = "InsertDate";
clmn.Caption = TsmDxWeb.Resources.InsertDate;
clmn.CellStyle.Wrap = DefaultBoolean.False;
clmn.Width = 150;
clmn.SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
});
output:
and group output:
grid group data by datetime, but I want to group them by only date.
If I add clmn.Settings.GroupInterval = DevExpress.XtraGrid.ColumnGroupInterval.Date;, no data shown in grouping. Because gridview add time '00.00.000' to dates.
Also, there is a gridviewSetting that named setting.CustomColumnGroup, but there is no example. I researched a lot for an example but, I could not find anything.
How can I group records only by date without time?
settings.Columns.Add(clmn =>
{
clmn.FieldName = "InsertDate";
clmn.Caption = TsmDxWeb.Resources.InsertDate;
clmn.CellStyle.Wrap = DefaultBoolean.False;
clmn.Width = 150;
clmn.SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
clmn.Settings.GroupInterval = DevExpress.XtraGrid.ColumnGroupInterval.Date;
});
"Rows are grouped by the date part of their values, the time portion is ignored"
I'm a beginner with dhtmlx scheduler, I use dbfirst with mvc4 razor syntax.
So please can anybody help me to set the start time and endtime values I'm getting from the database:
here is my code:
controller:
sched.Config.first_hour = 8;
sched.Config.last_hour = 19;
public string GetDbValues()
{
string strState = "";
List<tblSettings> settings = new List<tblSettings>();
settings = _config.GetSettings();
var defaultState = from setting in settings
where (setting.Desc == "start time"
|| setting.Desc == "end time")
// starttime as 08 and end time as 20 from database
select setting.Settings;
foreach (var oState in defaultState)
{strState += oState + "|";
}
strState = strState.Remove(strState.Length - 1);
return strState;
}
I get the values for first_hour and last_hour as string from the output.
How to assign this string value to the first_hour and last_hour?
//I use linq to get the db values because of the table structure:
ID(int), Settings(nvarchar) ,Desc (nvarchar)
why do you concatenate the settings into string? More comprehensive data format will simplify the task. You could return List as it is and then just iterate it with foreach, applying needed settings. If for some reason you don't want to pass tblSettings objects, you can select data into Dictionary and then again, apply the values
var data = _config.GetSettings().ToDictionary(
s => s.Desc,
s => s.Setting,
StringComparer.Ordinal);
if(data.ContainsKey("start time"))
scheduler.Config.first_hour = int.Parse(data["start time"]);
if (data.ContainsKey("end time"))
scheduler.Config.first_hour = int.Parse(data["end time"]);
i got problem with my LINQ to format date. Here is code
var resultCustomer = from row in formDg.dtCustomer.AsEnumerable()
where row.Field<int>("customerID") == customerID2
select new
{
name = row["customerName"].ToString(),
ic = row["customerIC"].ToString(),
add1 = row["customerAdd1"].ToString(),
add2 = row["customerAdd2"].ToString(),
tel = row["customerTel"].ToString(),
tel2 = row["customerTel2"].ToString(),
tel3 = row["customerTel3"].ToString(),
email = row["customerEmail"].ToString(),
dateRegister = row["customerDateRegister"].ToString(),
customerRef = row["customerRef"].ToString(),
customerGroup = row["groupCustName"].ToString(),
panelName = row["panelName"].ToString(),
};
var firstRecord = resultCustomer.First();// My record return single row only
My question is how i can format custom date like "dd/MM/yyyy" in customerDateRegister?, Because I got problem when my textbox show 16-Nov-12 12:00:00 AM. I don`t want to display time but just date only.
I have try like this tbDateRegOv.Text = firstRecord.dateRegister.ToString("dd/MM/yyyy");. not work. Then i try dateRegister = row["customerDateRegister"].ToString("dd/MM/yyyy"), in LINQ. Same problem.
So how can I solved this problem? Thanks for help. :)
You need to cast your row as a DateTime first. This will allow you to use the custom format strings for dates.
dateRegister = ((DateTime)row["customerDateRegister"]).ToString("dd/MM/yyyy")
If customerDateRegister is of type DateTime you should make it a DateTime in the first place. Therefor use the DataRow extension method Field<T>:
dateRegister = row.Field<DateTime>("customerDateRegister")
You could try this , replace your dateRegister line with this.
dateRegister = ((DateTime)row["customerDateRegister"]).ToString("dd/MM/yyyy"),
Or, you can use MaskedEditBox with the desired datetime mask