473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the function used to get the current time updated ??

111 100+
Hii all,

im doin a vb project where i need to update the current date..??


Expand|Select|Wrap|Line Numbers
  1. (vb)
  2.  
  3.   Private Function updateDate(ByVal strDate As String) As String
  4.         'to convert valid date format
  5.         Dim xdate As String
  6.         Try
  7.             xdate = "'" + Format(Convert.ToDateTime(strDate), "yyyy-MM-dd") + "'"
  8.         Catch ex As Exception
  9.             xdate = "'" + "0000-00-00" + "'"
  10.         End Try
  11.         updateDate = xdate
  12.         Return updateDate
  13.     End Function
  14.  
plz someone tell me wat changes i need to do to the code to get the current time....

thnq..
May 31 '07 #1
8 1845
Plater
7,872 Expert 4TB
What exactly are you trying to do? You keep using contradictory terms.

Getting the current date and time is as easy as:
Expand|Select|Wrap|Line Numbers
  1. DateTime rightnow= DateTime.Now;
  2. String mydatestring = rightnow.ToString();
  3. // .ToString() can take a number of different arguments that determine how and what gets displayed
  4.  
Setting the date and time for the computer that the software is running on is something that I don't know a good way to do.
You can run a proccess for command line commands: TIME and DATE
(open up a command prompt and type "help date" and "help time" to see more about them)
But there is probably a better way.
May 31 '07 #2
SammyB
807 Expert 512MB
Hii all,

im doin a vb project where i need to update the current date..??


Expand|Select|Wrap|Line Numbers
  1. (vb)
  2.  
  3. Private Function updateDate(ByVal strDate As String) As String
  4. 'to convert valid date format
  5. Dim xdate As String
  6. Try
  7. xdate = "'" + Format(Convert.ToDateTime(strDate), "yyyy-MM-dd") + "'"
  8. Catch ex As Exception
  9. xdate = "'" + "0000-00-00" + "'"
  10. End Try
  11. updateDate = xdate
  12. Return updateDate
  13. End Function
  14.  
plz someone tell me wat changes i need to do to the code to get the current time....

thnq..
If you want to display the date and/or time as a string, then just use the FormatDateTime function.
May 31 '07 #3
rhepsi
111 100+
What exactly are you trying to do? You keep using contradictory terms.

Getting the current date and time is as easy as:
Expand|Select|Wrap|Line Numbers
  1. DateTime rightnow= DateTime.Now;
  2. String mydatestring = rightnow.ToString();
  3. // .ToString() can take a number of different arguments that determine how and what gets displayed
  4.  
Setting the date and time for the computer that the software is running on is something that I don't know a good way to do.
You can run a proccess for command line commands: TIME and DATE
(open up a command prompt and type "help date" and "help time" to see more about them)
But there is probably a better way.
Hey sorry i want the current date in the format of "yyyy-MM-dd"
i have a function here:

{
Expand|Select|Wrap|Line Numbers
  1. vb}
  2.  
  3.  Private Function updateDate(ByVal strDate As String) As String
  4.         'to convert valid date format
  5.         Dim xdate As String
  6.         Try
  7. .....>>   xdate = "'" + Format(Convert.ToDateTime(strDate), "yyyy-MM-dd") + "'"....>>>     <<< doubt>>>
  8.  
  9.  Catch ex As Exception
  10.             xdate = "'" + "0000-00-00" + "'"
  11.         End Try
  12.         updateDate = xdate
  13.         Return updateDate
  14.     End Function
  15.  
  16.  

When im trying to execute the program im not getting the curent date but instead im getting null values as in the catch .....

Wat i need to do to get the actual or the current date.............???

thnx in advance
Jun 1 '07 #4
Hey sorry i want the current date in the format of "yyyy-MM-dd"
i have a function here:

{
Expand|Select|Wrap|Line Numbers
  1. vb}
  2.  
  3.  Private Function updateDate(ByVal strDate As String) As String
  4.         'to convert valid date format
  5.         Dim xdate As String
  6.         Try
  7. .....>>   xdate = "'" + Format(Convert.ToDateTime(strDate), "yyyy-MM-dd") + "'"....>>>     <<< doubt>>>
  8.  
  9.  Catch ex As Exception
  10.             xdate = "'" + "0000-00-00" + "'"
  11.         End Try
  12.         updateDate = xdate
  13.         Return updateDate
  14.     End Function
  15.  
  16.  

When im trying to execute the program im not getting the curent date but instead im getting null values as in the catch .....

Wat i need to do to get the actual or the current date.............???

thnx in advance
Hi,
instead of anothe function u can do it in one single line as below,
Dim str As String
str = Format(CDate((FormatDateTime(System.DateTime.Now, DateFormat.GeneralDate))), "yyyy-MM-dd")
And i tried ur code and its working fine and its not going into catch section.
even though if you are getting the error try to debug and see where its failing..
Jun 1 '07 #5
rhepsi
111 100+
Hi,
instead of anothe function u can do it in one single line as below,
Dim str As String
str = Format(CDate((FormatDateTime(System.DateTime.Now, DateFormat.GeneralDate))), "yyyy-MM-dd")
And i tried ur code and its working fine and its not going into catch section.
even though if you are getting the error try to debug and see where its failing..

Thanq so much... its working nw....
Jun 1 '07 #6
rhepsi
111 100+
Hi,
instead of anothe function u can do it in one single line as below,
Dim str As String
str = Format(CDate((FormatDateTime(System.DateTime.Now, DateFormat.GeneralDate))), "yyyy-MM-dd")
And i tried ur code and its working fine and its not going into catch section.
even though if you are getting the error try to debug and see where its failing..

Hii,

if im gonna update the existing date then... wat should be the difference..??
Jun 1 '07 #7
Plater
7,872 Expert 4TB
Hey sorry i want the current date in the format of "yyyy-MM-dd"
You guys made that WAY to over complex
Expand|Select|Wrap|Line Numbers
  1. string mydate=DateTime.Now.ToString("yyyy-MM-dd");
  2.  
This is from the msdn help on DateTime.ToString(String)-> DateTimeFormatInfo section:
[html]
Format Pattern
Description

d, %d
The day of the month. Single-digit days will not have a leading zero. Specify "%d" if the format pattern is not combined with other format patterns.

dd
The day of the month. Single-digit days will have a leading zero.

ddd
The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.

dddd
The full name of the day of the week, as defined in DayNames.

M, %M
The numeric month. Single-digit months will not have a leading zero. Specify "%M" if the format pattern is not combined with other format patterns.

MM
The numeric month. Single-digit months will have a leading zero.

MMM
The abbreviated name of the month, as defined in AbbreviatedMonthNames.

MMMM
The full name of the month, as defined in MonthNames.

y, %y
The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. Specify "%y" if the format pattern is not combined with other format patterns.

yy
The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.

yyyy
The year in four digits, including the century.

gg
The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.

h, %h
The hour in a 12-hour clock. Single-digit hours will not have a leading zero. Specify "%h" if the format pattern is not combined with other format patterns.

hh
The hour in a 12-hour clock. Single-digit hours will have a leading zero.

H, %H
The hour in a 24-hour clock. Single-digit hours will not have a leading zero. Specify "%H" if the format pattern is not combined with other format patterns.

HH
The hour in a 24-hour clock. Single-digit hours will have a leading zero.

m, %m
The minute. Single-digit minutes will not have a leading zero. Specify "%m" if the format pattern is not combined with other format patterns.

mm
The minute. Single-digit minutes will have a leading zero.

s, %s
The second. Single-digit seconds will not have a leading zero. Specify "%s" if the format pattern is not combined with other format patterns.

ss
The second. Single-digit seconds will have a leading zero.

f, %f
The fraction of a second in single-digit precision. The remaining digits are truncated. Specify "%f" if the format pattern is not combined with other format patterns.

ff
The fraction of a second in double-digit precision. The remaining digits are truncated.

fff
The fraction of a second in three-digit precision. The remaining digits are truncated.

ffff
The fraction of a second in four-digit precision. The remaining digits are truncated.

fffff
The fraction of a second in five-digit precision. The remaining digits are truncated.

ffffff
The fraction of a second in six-digit precision. The remaining digits are truncated.

fffffff
The fraction of a second in seven-digit precision. The remaining digits are truncated.

F, %F
Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. Specify "%F" if the format pattern is not combined with other format patterns.

FF
Displays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.

FFF
Displays the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.

FFFF
Displays the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.

FFFFF
Displays the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.

FFFFFF
Displays the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.

FFFFFFF
Displays the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.

t, %t
The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any. Specify "%t" if the format pattern is not combined with other format patterns.

tt
The AM/PM designator defined in AMDesignator or PMDesignator, if any.

z, %z
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is "-8". Specify "%z" if the format pattern is not combined with other format patterns.

zz
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will have a leading zero. For example, Pacific Standard Time is "-08".

zzz
The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is "-08:00".

:
The default time separator defined in TimeSeparator.

/
The default date separator defined in DateSeparator.

% c
Where c is a format pattern if used alone. That is, to use format pattern "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" by itself, specify "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".

The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns.

\ c
Where c is any character. Displays the character literally. To display the backslash character, use "\\".

[/html]
Jun 1 '07 #8
rhepsi
111 100+
You guys made that WAY to over complex
Expand|Select|Wrap|Line Numbers
  1. string mydate=DateTime.Now.ToString("yyyy-MM-dd");
  2.  
This is from the msdn help on DateTime.ToString(String)-> DateTimeFormatInfo section:
[html]
Format Pattern
Description

d, %d
The day of the month. Single-digit days will not have a leading zero. Specify "%d" if the format pattern is not combined with other format patterns.

dd
The day of the month. Single-digit days will have a leading zero.

ddd
The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.

dddd
The full name of the day of the week, as defined in DayNames.

M, %M
The numeric month. Single-digit months will not have a leading zero. Specify "%M" if the format pattern is not combined with other format patterns.

MM
The numeric month. Single-digit months will have a leading zero.

MMM
The abbreviated name of the month, as defined in AbbreviatedMonthNames.

MMMM
The full name of the month, as defined in MonthNames.

y, %y
The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. Specify "%y" if the format pattern is not combined with other format patterns.

yy
The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.

yyyy
The year in four digits, including the century.

gg
The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.

h, %h
The hour in a 12-hour clock. Single-digit hours will not have a leading zero. Specify "%h" if the format pattern is not combined with other format patterns.

hh
The hour in a 12-hour clock. Single-digit hours will have a leading zero.

H, %H
The hour in a 24-hour clock. Single-digit hours will not have a leading zero. Specify "%H" if the format pattern is not combined with other format patterns.

HH
The hour in a 24-hour clock. Single-digit hours will have a leading zero.

m, %m
The minute. Single-digit minutes will not have a leading zero. Specify "%m" if the format pattern is not combined with other format patterns.

mm
The minute. Single-digit minutes will have a leading zero.

s, %s
The second. Single-digit seconds will not have a leading zero. Specify "%s" if the format pattern is not combined with other format patterns.

ss
The second. Single-digit seconds will have a leading zero.

f, %f
The fraction of a second in single-digit precision. The remaining digits are truncated. Specify "%f" if the format pattern is not combined with other format patterns.

ff
The fraction of a second in double-digit precision. The remaining digits are truncated.

fff
The fraction of a second in three-digit precision. The remaining digits are truncated.

ffff
The fraction of a second in four-digit precision. The remaining digits are truncated.

fffff
The fraction of a second in five-digit precision. The remaining digits are truncated.

ffffff
The fraction of a second in six-digit precision. The remaining digits are truncated.

fffffff
The fraction of a second in seven-digit precision. The remaining digits are truncated.

F, %F
Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. Specify "%F" if the format pattern is not combined with other format patterns.

FF
Displays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.

FFF
Displays the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.

FFFF
Displays the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.

FFFFF
Displays the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.

FFFFFF
Displays the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.

FFFFFFF
Displays the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.

t, %t
The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any. Specify "%t" if the format pattern is not combined with other format patterns.

tt
The AM/PM designator defined in AMDesignator or PMDesignator, if any.

z, %z
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is "-8". Specify "%z" if the format pattern is not combined with other format patterns.

zz
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will have a leading zero. For example, Pacific Standard Time is "-08".

zzz
The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is "-08:00".

:
The default time separator defined in TimeSeparator.

/
The default date separator defined in DateSeparator.

% c
Where c is a format pattern if used alone. That is, to use format pattern "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" by itself, specify "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".

The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns.

\ c
Where c is any character. Displays the character literally. To display the backslash character, use "\\".

[/html]

Thnx so much ...

Hey i already have a date, if i want to update that date into other db then, wat shd be the changes..
Private Function updateDate(ByVal strDate As String) As String
'to convert valid date format
Dim xdate As String
Try
.....>>> xdate = DateTime.Now.ToString("yyyy-MM-dd") .....>> (DOUBT)
Catch ex As Exception
xdate = "'" + "0000-00-00" + "'"
End Try
updateDate= xdate
Return updateDate
End Function
Jun 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
12
by: Peter Morris | last post by:
What, exactly, is ASP? Is ANY dynamically generated HTML the same as ASP? Or does ASP have to be in a particular format or language? The company I used to work for (until it went bust) was in...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
34
by: radink | last post by:
Well, I've got my DB ready to go. Now what? I need to host it on our Win2003 server. How do clients use it? I think im getting more confused as I try to figure this out. We are a small company...
3
by: Kurt | last post by:
Hi, I'd like advices about an idea I add to resolve a problem. thanks to you in advance for yours answers. I have a database with tables that I load with flat file. The size of each table is...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
8
by: Nick | last post by:
Hi there, Membership.GetNumberOfUsersOnline() works great the first time, then jumps up to the number of users registered in the system. I have tried enumerating through each user individually...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.