Visual Basic.NET - fechas/horas

 
Vista:

fechas/horas

Publicado por jorge (3 intervenciones) el 12/12/2007 22:12:23
bien agradesco tu respuesta, pero el tema es le suguiente estoy desarrollando para un examen un sistema de control de asistancia en visual NET 2003; tengo definida un parde tablasd e una base de datos sql server 2000 realizo la conexion ala base extraigo el rut lo asigno a un combo, en otro combo tengi una lista con ebtrada y salida. la hoa la tomodel sistema Dim = now ; despues se la asigno a un label, de esta foma label12.text = now.

el tema esta en que tengo otra tabla asistencia ,donde tengo que almacenar rut , facha , correlaticvo, e/s, hora ingreso, hora salida.

¿ hasta aqui llegan mis conocimientos, nose com separar la fecha de la hora para almacenarla en sus correspondientes campors de la base de datos ?

me puedes ayudar ?????
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:fechas/horas

Publicado por P. J. (706 intervenciones) el 12/12/2007 23:09:48
....

ACOMODANDO:

Asignas datos del Sistema a un LABEL, luego para guardar debes separar FECHA y HORA de ese LABEL?

Si es asi prueba con lo sgte:

Me.lblHora.Text = Now ' asi asignaste ¿no?
MsgBox("FECHA: " & Format(Convert.ToDateTime(Me.lblHora.Text), "dd/MM/yyyy") & vbCrLf & _
"HORA: " & Format(Convert.ToDateTime(Me.lblHora.Text), "hh:mm:ss tt"))

Alli te mostrara Fecha y Hora separados, tomados desde el label.

Salu2.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:fechas/horas

Publicado por jorge (3 intervenciones) el 13/12/2007 02:04:45
Imports System.Data.SqlClient
Imports System.Data
Imports System.text
Imports System.Web.UI.Control
Imports System.Reflection
Public Class Asistencias
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label12 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label11 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents cmb_rut As System.Web.UI.WebControls.DropDownList
Protected WithEvents cmb_peri As System.Web.UI.WebControls.DropDownList
Protected WithEvents lbl_rut As System.Web.UI.WebControls.Label
Protected WithEvents lbl_accion As System.Web.UI.WebControls.Label
Protected WithEvents btn_Cancelar As System.Web.UI.WebControls.ImageButton
Protected WithEvents btn_Ingresar As System.Web.UI.WebControls.ImageButton
Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents Regularexpressionvalidator2 As System.Web.UI.WebControls.RegularExpressionValidator

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Dim unRegistro As DataRow
Dim unaTabla As New DataTable
Dim unReader As SqlDataReader
Dim Con1 As New gestran.Parametros
Dim conexion As New SqlConnection(Con1.StrConexion)
Dim SSQL As String
Dim valor As String
Dim i As Integer
Dim Mensaje As New gestran.Mensaje
Dim rut As String
Dim a As Integer
Dim ano As String
Dim mes As String
Dim dia As String
Dim Mes_ceros As String
Dim Dia_ceros As String
Private hora_E As String
Private hora_S As String
Private hrr_ini As String
Private hrr_fin As String

'*********************CARGA LA PAGINA*************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request.Cookies("Usuario") Is Nothing Then
Response.Redirect("login.aspx")
End If

If Not IsPostBack Then
'mostrarDatos()
'*****************************EXTRAE LA HORA DEL SISTEMA Y LA ASIGNA A UN LABEL******************************
'Dim x = Now
'Label12.Text = Now
'Label12.Text = Date.Now.ToLongDateString
'Label12.Text = Date.Now.ToLongDateString & " " & Date.Now.ToLongTimeString

Label12.Text = Date.Now

poblarRut()
'verifica_entrada()
End If
End Sub

Public Sub poblarRut()
'*****************************************CREA CONEXION CON LA BASE DE DATOS****************************

SSQL = "Select Distinct rut from BGTM_TBL..personalcajas"

Dim micommand As New SqlCommand(SSQL, conexion)

Try
conexion.Open()
unReader = micommand.ExecuteReader
Catch ex As Exception
Response.Redirect("Error.aspx")
End Try

cmb_rut.Items.Add("--")
cmb_rut.Items(0).Value = "--"
i = 1

While unReader.Read
valor = Trim(unReader(0))
cmb_rut.Items.Add(Trim(unReader(0)))
cmb_rut.Items(i).Value = valor
i += 1
End While

conexion.Close()
unReader.Close()

End Sub

Public Sub msg(ByVal texto As String)

Dim frameScript As String = "<script language='JavaScript'>" & _
"alert('" & texto & "');</script>"
Page.RegisterStartupScript("Alert", frameScript)

End Sub

Private Sub cmb_rut_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_rut.SelectedIndexChanged
lbl_rut.Text = cmb_rut.SelectedItem.Text
lbl_rut.Visible = True
cmb_rut.Visible = False
End Sub

Private Sub cmb_peri_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_peri.SelectedIndexChanged
lbl_accion.Text = cmb_peri.SelectedItem.Text
lbl_accion.Visible = True
cmb_peri.Visible = False
End Sub

'Private Sub btn_Ingresar_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_Ingresar.Click
' If Regularexpressionvalidator2.IsValid = True And RegularExpressionValidator1.IsValid = True Then
' If Trim(cmb_rut.SelectedItem.Text) = "" Or Trim(cmb_peri.SelectedItem.Text) = "" Then
' Mensaje.msg("No debe quedar ningún campo en blanco", Me)
' Exit Sub
' End If
' Else
' Actualiza_ingresa()
' End If

'End Sub
'Public Sub Actualiza_ingresa()
' rut = cmb_rut.SelectedItem.Text
' a = cmb_peri.SelectedValue


' Mensaje.msg("Su entr " & a & " ya se Encuentra en Nuestra Base de Datos ", Me)

' Mensaje.msg("La transacción " & a & " ha sido Modificada Satisfactoriamente", Me)

' Mensaje.msg("La transacción " & a & " ha sido Ingresada Satisfactoriamente", Me)

'Me.Label12.Text = Now ' asi asignaste ¿no?
' MsgBox("FECHA: " & Format(Convert.ToDateTime(Me.Label12.Text), "dd/MM/yyyy") & vbCrLf & _
' "HORA: " & Format(Convert.ToDateTime(Me.Label12.Text), "hh:mm:ss tt"))

'End Sub

'qui muestro la fecha y hora en un MSGBOX

'MsgBox("FECHA: " & Date.Now.ToString("dd/MM/yyyy") & vbCrLf & _
'"HORA: " & Date.Now.ToString("hh:mm:ss tt"))

'Para la hora si pones HH sera la hora corrida 1=13, 2=14, etc
'y el tt es para mostrar el a.m. y p.m.

End Class


asi tengo definod lo expuesto no me funciona con el codigo que recibi, alguna orientacion ke es la primera vez que programo con visual NET 2003

Label12.Text = Date.Now ------asi le asigne la fecha al label mela muestra por pantalla de la sigte manera --- 12/12/2007 21:59:44----, ahora lo que intento hacer y no se es tomar segun elformato de datos del SQL yyyymmdd-- toamr el año e dejarlo en a variable ano, mes en la variable mes etc y la hora ahora ley por hay un metodo date diff , tenog que validar que al hora de entrada sea menor que la de salida , despues calcular horas trabajas , no trabajadas, etc pero eso es harina de otro costal asi que si me puede orientar te lo agradesco no me resuelvas solso orientame

salu2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:fechas/horas

Publicado por P. J. (706 intervenciones) el 13/12/2007 15:48:51
!!!

EN NINGUNO DE TUS OTROS MENSAJES NOS MENCIONASTE QUE ES UNA APLICACION WEB!.

Este es un foro para Aplicaciones Windows. (El foro de ASPX ta mas arribita)

Ahorita no tengo instalado el ASPX sino te ayudaria :D, pero igual si tu quieres separar fecha y hora o mes, anyo, dia, minutos, segundos de cualquier control debes de probar aplicando FORMAT, otra forma es separando cadenas con SUBSTRING

Dim strAnyo As String = Me.lblHora.Text.Substring(0, 2)
Dim strMes As String = Me.lblHora.Text.Substring(3, 2)
Dim strDia As String = Me.lblHora.Text.Substring(6, 5)

Dim strHora As String = Me.lblHora.Text.Substring(10, 9)

Espero te funcione, y ojala eso sea XD
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:fechas/horas

Publicado por Harold V. (411 intervenciones) el 14/12/2007 01:27:58
Hola: Espero esto te ayude...

ConvertToyyyymmdd= Te obtiene el formato que deseas yyyymmdd
DiferenciaEnDias= Te devuelve la resta entre las fechas en dias.

MsgBox(Me.ConvertToyyyymmdd("01/12/2007"))

'si tus valores son texto los conviertes a date, sino los colocas como tal
Dim fecing, fecsal As DateTime
fecing = CDate(Me.txtingreso.text)
fecsal = CDate(Me.txtsalida.text)

MsgBox(DiferenciaEnDias(fecing, fecsal))


Function ConvertToyyyymmdd(ByVal fecha As String) As String
Dim _fecha As Date = CDate(fecha)
Dim año, mes, dia As Integer
Dim result As String

año = _fecha.Year
mes = _fecha.Month
dia = _fecha.Day

result = año & mes & dia

Return result
End Function

Function DiferenciaEnDias(ByVal fechaingreso As Date, ByVal fechasalida As Date) As Integer
Dim result As Integer = DateDiff(DateInterval.Day, fechaingreso, fechasalida)

Return result
End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:fechas/horas

Publicado por estephan (1 intervención) el 29/01/2008 19:00:52
resuelba un ejercicio en el cual me muestre la edad de la persona
poniendo su fecha de nacimiento
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar