Question : datetime.now as date

trying to use datetime.now to represent date in filename for a daily log

Private Sub passed24hours()
        Dim d As Date = starttime
        Dim filename As String

        d.AddDays(1)
        If Date.Compare(Now, d) <= 0 Then
            ' 24hours have passed
            filename = String.Format("c:\\ians\\{0:g}log.csv", DateTime.Now.Day)
            outfile = New StreamWriter(filename, False)

            timer1.Stop()
        Else
            ' 24hours(Not passed)
            filename = String.Format("c:\\ians\\{0:g}log.csv", DateTime.Now.Day)

            If File.Exists(filename) Then
                outfile = New StreamWriter(filename, True)
            Else
                outfile = New StreamWriter(filename, False)
            End If
        End If
    End Sub

getting it working with .day gives my 19log.csv using .dayofyear gives me 200 for instance how can I use it to say 17julylog.csv

Answer : datetime.now as date

Your time values are formatted as text, so when you use a formula like B2+B3 that will "coerce" text that looks like a time value to a real time value. You can use a formula like this to convert:

=SUMPRODUCT(($A$2:$A$548="Cleaning")*$B$2:$B$548)

format result cell as [h]:mm

...or you can convert the text value to time values like this

Select column B > Data > Text to Columns > Finish

Now your original SUMIF formula will work

regards, barry

Random Solutions  
 
programming4us programming4us