Mostrando las entradas con la etiqueta DateTime. Mostrar todas las entradas
Mostrando las entradas con la etiqueta DateTime. Mostrar todas las entradas

martes, 17 de diciembre de 2019

validar formato hora

Dim time As DateTime
        Dim valid As Boolean = DateTime.TryParseExact("00:05:00", "hh:mm:ss", CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, time)


fuente

martes, 12 de noviembre de 2019

última modificación

Dim filepath As String = Assembly.GetExecutingAssembly().Location
        Dim dt As DateTime = New FileInfo(filepath).LastWriteTime
        MessageBox.Show(dt.ToString("HH:mm:ss dd-MM-yyyy"))


fuente

jueves, 17 de octubre de 2019

suma y resta día


formato entrada fecha=20191017

Public Function suma_resta_dia(ByVal fecha As String, ByVal dias As Integer) As Integer
        fecha = fecha.Insert(4, "-").Insert(7, "-")
        Dim dt As DateTime = DateTime.Parse(fecha).AddDays(dias)
        Return dt.ToString("yyyyMMdd")
    End Function

martes, 15 de octubre de 2019

fecha máxima

DateTimePicker.MaxDate = DateTime.Today

cambiar formato fecha


fecha='20191009

Public Function get_fecha_inicio(ByVal fecha As String) As String
        Dim tmp As String = ""
        tmp += fecha.Substring(6, 2) & "-"
        tmp += fecha.Substring(4, 2) & "-"
        tmp += fecha.Substring(0, 4)
        Return tmp
    End Function

miércoles, 20 de febrero de 2019

convertir string a DateTime

Dim fecha_autorizacion As String = "2019-01-05"
DateTime.Parse(fecha_autorizacion).AddMonths(6).ToString("yyyy-MM-dd")

miércoles, 28 de noviembre de 2018

lunes, 27 de agosto de 2018

Carpeta respaldo

Public Function folderBkp(ByVal ruta As String) As String
        Dim newFolder As String = Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
        ruta = ruta & "\" & newFolder
        If Not Directory.Exists(ruta) Then
            Directory.CreateDirectory(ruta)
        End If
        Return ruta
    End Function

Public Function folderBkp(ByVal ruta As String) As String
        ruta = ruta & "\" & Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
        If Not Directory.Exists(ruta) Then
            Directory.CreateDirectory(ruta)
        End If
        Return ruta
    End Function

martes, 21 de agosto de 2018

formato fecha

fechaInicial = DateTime.Now.AddMonths(-1).ToString("yyyyMMdd")
fechaFinal = DateTime.Now.ToString("yyyyMMdd")

miércoles, 13 de junio de 2018

Comparar fechas

Dim fs As DateTime = Convert.ToDateTime("2018-08-10").Date
Dim fh As DateTime = Convert.ToDateTime("2018-05-14").Date

If fs > fh Then
MessageBox("ok")
End If

Public Function compareDate(ByVal fechaInicial As String, ByVal fechaActual As String) As Integer
        Dim result As Integer = 0
        Dim dif As TimeSpan = Convert.ToDateTime(fechaActual) - Convert.ToDateTime(fechaInicial)
        Dim nDays As Integer = dif.Days
        If nDays = 0 Then
            result = 0
            'MessageBox.Show("Es el mismo día")
        ElseIf nDays > 0 Then
            result = 1
            'MessageBox.Show("La fecha actual es mayor")
        ElseIf nDays < 0 Then
            result = -1
            'MessageBox.Show("La fecha inicial es mayor")
        End If
        Return result
    End Function

jueves, 26 de abril de 2018

miércoles, 25 de abril de 2018

Obtener el día anterior; fecha

Dim diaAnterior As DateTime = Now.ToString("dd-MM-yyyy")
        diaAnterior = diaAnterior.AddDays(-1)
        MessageBox.Show(diaAnterior.ToString("dd-MM-yyyy"))

Ejemplo 2
Dim diaAnterior As String = (Convert.ToDateTime(Now.ToString("dd-MM-yyyy")).AddDays(-1)).ToString("dd-MM-yyyy")

Ejemplo 3
Dim diaAnterior As String = Now.AddDays(-1).ToString("dd-MM-yyyy")

Ejemplo 4
Dim ayer As String = DateTime.Today.AddDays(-1).ToString("dd-MM-yyyy")

martes, 10 de octubre de 2017

Cambiar formato de fecha obtenida de SQL

Dim fechaservidor As String ='10/10/2017'

fechaservidor = DateTime.ParseExact(fechaservidor, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")

martes, 3 de octubre de 2017

Ingresar una fecha y obtener el mes en palabras

Imports System.Globalization
Dim mes As String = New DateTime(2017, 2, 31).ToString("MMMM", CultureInfo.CreateSpecificCulture("es"))

Seleccionar el mes en palabras y obtener su número

Imports System.Globalization
Dim mes As String = DateTime.ParseExact("octubre", "MMMM", CultureInfo.CreateSpecificCulture("es")).Month.ToString.PadLeft(2, "0")

jueves, 28 de septiembre de 2017

validar formato fecha

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim fecha As String = tbfecha.Text.Trim

Dim formats() As String = {"d-MM-yyyy", "dd-MM-yyyy",
      "dd-M-yyyy", "d-M-yyyy"} ' más de un formato

Dim format As String = "dd-MM-yyyy"
        Dim thisDT As DateTime = Nothing

        If DateTime.TryParseExact(fecha, format, Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, thisDT) Then

            MessageBox.Show("ok!")

        Else

            MessageBox.Show("no!")
        End If
End Sub

fuente: https://stackoverflow.com/questions/24841806/validate-the-date-format-in-vb-net