473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

111 New Member
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 1857
Plater
7,872 Recognized Expert Expert
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 Recognized Expert Contributor
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 New Member
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
dskinibbyb
8 New Member
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((F ormatDateTime(S ystem.DateTime. Now, DateFormat.Gene ralDate))), "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 New Member
Hi,
instead of anothe function u can do it in one single line as below,
Dim str As String
str = Format(CDate((F ormatDateTime(S ystem.DateTime. Now, DateFormat.Gene ralDate))), "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 New Member
Hi,
instead of anothe function u can do it in one single line as below,
Dim str As String
str = Format(CDate((F ormatDateTime(S ystem.DateTime. Now, DateFormat.Gene ralDate))), "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 Recognized Expert Expert
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.ToStri ng(String)-> DateTimeFormatI nfo 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 AbbreviatedDayN ames.

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 AbbreviatedMont hNames.

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 New Member
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.ToStri ng(String)-> DateTimeFormatI nfo 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 AbbreviatedDayN ames.

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 AbbreviatedMont hNames.

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(ByVa l strDate As String) As String
'to convert valid date format
Dim xdate As String
Try
.....>>> xdate = DateTime.Now.To String("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
6539
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 FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
12
3642
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 the business of creating dynamic websites for companies, using our own proprietry set of development tools, which was called Bladerunner. (You probably won't have heard of it) Heres a website I helped to create for one of our few
125
14658
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
51
4493
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 there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
34
2479
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 and I just want to be able to have everyone here use the database at the same time without too much fuss. Do I just have to have access on each machine and let them open it from the server, or is there more to it than that? I just don't want them...
3
6423
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 600 Mb. The flat file are the image of an application and there is no updated date or created date on any table. So my tables are just a copy of the data from the flat file. Now I'd like to create an History Table. So I have to determine which
167
8239
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 object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
4
3851
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 am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
8
3750
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 and checking IsOnline which done likewise, first result was 4, then 22 every time after that and it's only be debugging locally using VS. Either I'm doing something seriously wrong or this function is a
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.