locked
can't retrieve date only from datepicker ... always with time RRS feed

  • Question

  • Hi,

    probably simple, but can't seem to figure it out ...

    I have a DatePicker and I want to get the date value from it, so I do this:

    ExactDate = Format(datePickerFrom.Value, "M/d/yyyy")

    But the end result as you can see below:

    Anyone can help?

    I want to find some files with an exact date but the time is making it miss the files

    Thanks


    • Edited by Alex Cote Thursday, June 11, 2020 2:00 PM added image
    Thursday, June 11, 2020 12:08 PM

Answers

  • ZipArchiveEntry has LastWriteTime 

    Dim data = New DateTimeOffset(Now)
    Console.WriteLine($"{data.ToString("d")}")
    So for today we get 6/11/2020


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Alex Cote Thursday, June 11, 2020 5:24 PM
    Thursday, June 11, 2020 3:44 PM

All replies

  • Hi,

    probably simple, but can't seem to figure it out ...

    I have a DatePicker and I want to get the date value from it, so I do this:

    ExactDate = Format(datePickerFrom.Value, "M/d/yyyy")

    But the end result as you can see below:

    Anyone can help?

    I want to find some files with an exact date but the time is making it miss the files

    Thanks

    Hi

    See what? Maybe I am going blind but I think there is nothing to 'see below'

    I tried your code and seems no issue here with it. I used the default name for the DateTimePicker1.

    Here is what I tried and showing result (actually visible)

    The full value of the DTP was #6/11/2020 01:54:24 PM#

        Dim ExactDate As String = Format(DateTimePicker1.Value, "M/d/yyyy")
    
        ' result = "6/11/2020"
    

    Here is one with hours minutes and seconds showing:

        Dim ExactDate2 As String = Format(DateTimePicker1.Value, "M/d/yyyy HH:mm:s")
    
        ' result = "6/11/2020 13:56:15"
    


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, June 11, 2020 12:57 PM
    Thursday, June 11, 2020 12:52 PM
  • Something like this where you can change LastAccessTime to CreationTime, LastWriteTime etc.

    Dim info As New DirectoryInfo("Your path")
    Dim files() As FileInfo = info.GetFiles().
            Where(Function(p) p.LastAccessTime.ToString("d") = DateTimePicker1.Value.ToString("d")).
            OrderBy(Function(p) p.CreationTime).
            ToArray()
    
    For Each file As FileInfo In files
        Console.WriteLine($"{file.Name}, {file.LastAccessTime:d}")
    Next


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 11, 2020 1:19 PM
  • yep my bad forgot the image .... it's there now
    Thursday, June 11, 2020 2:01 PM
  • I did the same check you shown and do get the same result:

    but later in the code, the value of "ExactDate" still include the time stamp

    Thursday, June 11, 2020 2:55 PM
  • Hi,

    not sure how I would implement that because I am using the dates from files and also for ZipArchiveEntry which are DateTimeOffset that I convert to DateTime (with a solution found on this forum).

    i can't figure out why if I print in output windows it shows correctly but when using it still contain the time stamp.

    Then

    Thursday, June 11, 2020 2:59 PM
  • That's good, but when is a Heuristic-Parse syntax the better choice?

    I don't recall but the odd looking "\{blah$$}\#$c/$c/$c!" kind.

    Thanks



    Thursday, June 11, 2020 3:17 PM
  • This has similarities but it is different too with your question.

    In C++, the cerr object outputs to an error device or printer. But in MS-Visual C++ 98 it always goes to the console like cout! If you try to change the address it shows an error. Weird

    But in real Computer Programming, any error should go straight to a printer in real-time.

    Like they were doing for post-Altair and dot-matrix printers (may do a history check.)

    Thursday, June 11, 2020 3:29 PM
  • ZipArchiveEntry has LastWriteTime 

    Dim data = New DateTimeOffset(Now)
    Console.WriteLine($"{data.ToString("d")}")
    So for today we get 6/11/2020


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Alex Cote Thursday, June 11, 2020 5:24 PM
    Thursday, June 11, 2020 3:44 PM
  • Thanks Karen for this syntax.

    I guess I was a bit slow on this one, did not thought to apply the same syntax to the file date to get both date at 12:00:00AM ... was doing it only on the date picker value !

    Thursday, June 11, 2020 5:23 PM