Forum Discussion

1 Reply

  • Hi hitnvhd 

     

    Date & time format are return based in on your system date & time settings, pls check the same it will be as DD/MM/YYY HH:MM. If you don't wish to disturb your system setting then use the format function to format the date.

     

    Declare the variable a as Date instead of string.

     

    Without formatting 

    Private Sub CommandButton1_Click()
    
    Dim a As Date
    
    a = Now
    
    ActiveSheet.Range("b2").Value = a
    
    End Sub

     

    With Formatting 

    Private Sub CommandButton1_Click()
    
    Dim a As Date
    
    a = Now
    ActiveSheet.Range("b2").Value = Format(a, "MM/DD/YYY HH:MM")
    
    End Sub

     

    Regards, Faraz Shaikh | MCT, MIE, MOS Master, Excel Expert

    If you find the above solution resolved your query don't forget mark as Official Answer to help the other members find it more

Resources