here is the code, now I have 2 datetime pickers, set on Time (dtFrom, dtTo), I want them…
- User
here is the code, now I have 2 datetime pickers, set on Time (dtFrom, dtTo), I want them to get timestamp value for the selected type, and in format to include also milliseconds
namespace Project1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); InitializeComboBox(); numDataPointCount.ValueChanged += UpdateChartAndData; cmbSelection.SelectedIndexChanged += UpdateChartAndData; } public class AxisRange { public Types Type { get; } public int Min { get;} public int Max { get; } public AxisRange(Types type, int min, int max ) { Type = type; Min = min; Max = max; } } public readonly List yAxisRange = new List() //Min max value for each type , used for configuring the range of values in Y-axis { new AxisRange(Types.BOOL, 0, 1), new AxisRange(Types.BYTE, 0, 255), new AxisRange(Types.WORD, 0, 65535), new AxisRange(Types.DWORD, 0, int.MaxValue), new AxisRange(Types.LWORD, 0, int.MaxValue), new AxisRange(Types.SINT, -128, 127), new AxisRange(Types.USINT, 0, 255), new AxisRange(Types.INT, -32768, 32767), new AxisRange(Types.UINT, 0, 65535), new AxisRange(Types.DINT, int.MinValue, int.MaxValue), new AxisRange(Types.UDINT, 0, int.MaxValue), new AxisRange(Types.LINT, int.MinValue, int.MaxValue), new AxisRange(Types.ULINT, 0, int.MaxValue), new AxisRange(Types.REAL, -100000, 100000), new AxisRange(Types.LREAL, -100000, 100000), new AxisRange(Types.STRING, 0, 100), new AxisRange(Types.WSTRING, 0, 100), new AxisRange(Types.TIME, 0, 86400), new AxisRange(Types.LTIME, 0, int.MaxValue), new AxisRange(Types.DATE, 0, 365), new AxisRange(Types.DT, 0, 365), new AxisRange(Types.TOD, 0, 86400) }; public string GetColumnName (Types type) //Mapping (selecting and retrieving data from the database) { switch (type) { case Types.BOOL: case Types.BYTE: case Types.WORD: case Types.DWORD: case Types.SINT: case Types.USINT: case Types.INT: case Types.UINT: case Types.DINT: case Types.UDINT: case Types.TIME: case Types.DATE: case Types.DT: case Types.TOD: return "int32"; case Types.LWORD: case Types.LINT: case Types.ULINT: case Types.LTIME: return "int64"; case Types.REAL: return "floating32"; case Types.LREAL: return "floating64"; case Types.STRING: case Types.WSTRING: return "stringType"; default: throw new ArgumentOutOfRangeException (nameof (type), $"No mapping found for {type}"); } } private void InitializeComboBox() //ComboBox adjustments { cmbSelection.Items.Add("Select Type"); cmbSelection.Items.AddRange(Enum.GetNames (typeof (Types))); cmbSelection.SelectedIndex = 0; } private void UpdateChartAndData(object sender, EventArgs e) { if (cmbSelection.SelectedIndex > 0) { Types selectedType; if (Enum.TryParse(cmbSelection.SelectedItem.ToString(), out selectedType)) { int parameterID = (int)selectedType; string columnName = GetColumnName(selectedType);
code - Assistant
To get the timestamp value from your
DateTimePickercontrols ( and ) and ensure the format includes milliseconds, you can use the property of the and format it appropriately using the method. Here's how you might adjust your code to retrieve and display the timestamp in a format that includes milliseconds.